<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>experiments</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        Module&nbsp;experiments
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="experiments-pysrc.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<h1 class="epydoc">Source Code for <a href="experiments-module.html">Module experiments</a></h1>
<pre class="py-src">
<a name="L1"></a><tt class="py-lineno">  1</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">sys</tt><tt class="py-op">;</tt> </tt>
<a name="L2"></a><tt class="py-lineno">  2</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">binascii</tt><tt class="py-op">;</tt> </tt>
<a name="L3"></a><tt class="py-lineno">  3</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">array</tt><tt class="py-op">;</tt> </tt>
<a name="L4"></a><tt class="py-lineno">  4</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">csv</tt><tt class="py-op">,</tt> <tt class="py-name">time</tt><tt class="py-op">,</tt> <tt class="py-name">argparse</tt><tt class="py-op">;</tt> </tt>
<a name="L5"></a><tt class="py-lineno">  5</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">datetime</tt> </tt>
<a name="L6"></a><tt class="py-lineno">  6</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">os</tt> </tt>
<a name="L7"></a><tt class="py-lineno">  7</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">random</tt> <tt class="py-keyword">import</tt> <tt class="py-name">randrange</tt> </tt>
<a name="L8"></a><tt class="py-lineno">  8</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">random</tt> </tt>
<a name="L9"></a><tt class="py-lineno">  9</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-0" class="py-name" targets="Module GoodFETMCPCAN=GoodFETMCPCAN-module.html,Class GoodFETMCPCAN.GoodFETMCPCAN=GoodFETMCPCAN.GoodFETMCPCAN-class.html"><a title="GoodFETMCPCAN
GoodFETMCPCAN.GoodFETMCPCAN" class="py-name" href="#" onclick="return doclink('link-0', 'GoodFETMCPCAN', 'link-0');">GoodFETMCPCAN</a></tt> <tt class="py-keyword">import</tt> <tt id="link-1" class="py-name"><a title="GoodFETMCPCAN
GoodFETMCPCAN.GoodFETMCPCAN" class="py-name" href="#" onclick="return doclink('link-1', 'GoodFETMCPCAN', 'link-0');">GoodFETMCPCAN</a></tt><tt class="py-op">;</tt> </tt>
<a name="L10"></a><tt class="py-lineno"> 10</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-2" class="py-name" targets="Module GoodFETMCPCANCommunication=GoodFETMCPCANCommunication-module.html,Class GoodFETMCPCANCommunication.GoodFETMCPCANCommunication=GoodFETMCPCANCommunication.GoodFETMCPCANCommunication-class.html"><a title="GoodFETMCPCANCommunication
GoodFETMCPCANCommunication.GoodFETMCPCANCommunication" class="py-name" href="#" onclick="return doclink('link-2', 'GoodFETMCPCANCommunication', 'link-2');">GoodFETMCPCANCommunication</a></tt> <tt class="py-keyword">import</tt> <tt id="link-3" class="py-name"><a title="GoodFETMCPCANCommunication
GoodFETMCPCANCommunication.GoodFETMCPCANCommunication" class="py-name" href="#" onclick="return doclink('link-3', 'GoodFETMCPCANCommunication', 'link-2');">GoodFETMCPCANCommunication</a></tt> </tt>
<a name="L11"></a><tt class="py-lineno"> 11</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">intelhex</tt> <tt class="py-keyword">import</tt> <tt class="py-name">IntelHex</tt><tt class="py-op">;</tt> </tt>
<a name="L12"></a><tt class="py-lineno"> 12</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">Queue</tt> </tt>
<a name="L13"></a><tt class="py-lineno"> 13</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">math</tt> </tt>
<a name="L14"></a><tt class="py-lineno"> 14</tt>  <tt class="py-line"> </tt>
<a name="L15"></a><tt class="py-lineno"> 15</tt>  <tt class="py-line"><tt class="py-name">tT</tt> <tt class="py-op">=</tt> <tt class="py-name">time</tt> </tt>
<a name="L16"></a><tt class="py-lineno"> 16</tt>  <tt class="py-line"> </tt>
<a name="L17"></a><tt class="py-lineno"> 17</tt>  <tt class="py-line"> </tt>
<a name="experiments"></a><div id="experiments-def"><a name="L18"></a><tt class="py-lineno"> 18</tt> <a class="py-toggle" href="#" id="experiments-toggle" onclick="return toggle('experiments');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="experiments.experiments-class.html">experiments</a><tt class="py-op">(</tt><tt class="py-base-class">GoodFETMCPCANCommunication</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments-collapsed" style="display:none;" pad="+++" indent="++++"></div><div id="experiments-expanded"><a name="L19"></a><tt class="py-lineno"> 19</tt>  <tt class="py-line">    <tt class="py-docstring">""" </tt> </tt>
<a name="L20"></a><tt class="py-lineno"> 20</tt>  <tt class="py-line"><tt class="py-docstring">    This class provides methods for reverse-engineering the protocols on the CAN bus network</tt> </tt>
<a name="L21"></a><tt class="py-lineno"> 21</tt>  <tt class="py-line"><tt class="py-docstring">    via the GOODTHOPTER10 board, U{http://goodfet.sourceforge.net/hardware/goodthopter10/}    </tt> </tt>
<a name="L22"></a><tt class="py-lineno"> 22</tt>  <tt class="py-line"><tt class="py-docstring">    </tt> </tt>
<a name="L23"></a><tt class="py-lineno"> 23</tt>  <tt class="py-line"><tt class="py-docstring">    """</tt> </tt>
<a name="L24"></a><tt class="py-lineno"> 24</tt>  <tt class="py-line">     </tt>
<a name="experiments.__init__"></a><div id="experiments.__init__-def"><a name="L25"></a><tt class="py-lineno"> 25</tt> <a class="py-toggle" href="#" id="experiments.__init__-toggle" onclick="return toggle('experiments.__init__');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="experiments.experiments-class.html#__init__">__init__</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">data_location</tt> <tt class="py-op">=</tt> <tt class="py-string">"../../contrib/ThayerData/"</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments.__init__-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="experiments.__init__-expanded"><a name="L26"></a><tt class="py-lineno"> 26</tt>  <tt class="py-line">        <tt class="py-docstring">""" </tt> </tt>
<a name="L27"></a><tt class="py-lineno"> 27</tt>  <tt class="py-line"><tt class="py-docstring">        Constructor</tt> </tt>
<a name="L28"></a><tt class="py-lineno"> 28</tt>  <tt class="py-line"><tt class="py-docstring">        @type data_location: string</tt> </tt>
<a name="L29"></a><tt class="py-lineno"> 29</tt>  <tt class="py-line"><tt class="py-docstring">        @param data_location: path to the folder where data will be stored</tt> </tt>
<a name="L30"></a><tt class="py-lineno"> 30</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<a name="L31"></a><tt class="py-lineno"> 31</tt>  <tt class="py-line">        <tt id="link-4" class="py-name"><a title="GoodFETMCPCANCommunication
GoodFETMCPCANCommunication.GoodFETMCPCANCommunication" class="py-name" href="#" onclick="return doclink('link-4', 'GoodFETMCPCANCommunication', 'link-2');">GoodFETMCPCANCommunication</a></tt><tt class="py-op">.</tt><tt id="link-5" class="py-name" targets="Method DataManage.DataManage.__init__()=DataManage.DataManage-class.html#__init__,Method FordExperiments.FordExperiments.__init__()=FordExperiments.FordExperiments-class.html#__init__,Method GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.__init__()=GoodFETMCPCANCommunication.GoodFETMCPCANCommunication-class.html#__init__,Method experiments.experiments.__init__()=experiments.experiments-class.html#__init__,Method mainDisplay.DisplayApp.__init__()=mainDisplay.DisplayApp-class.html#__init__,Method mainDisplay.settingsDialog.__init__()=mainDisplay.settingsDialog-class.html#__init__,Method tkHyperlinkManager.HyperlinkManager.__init__()=tkHyperlinkManager.HyperlinkManager-class.html#__init__"><a title="DataManage.DataManage.__init__
FordExperiments.FordExperiments.__init__
GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.__init__
experiments.experiments.__init__
mainDisplay.DisplayApp.__init__
mainDisplay.settingsDialog.__init__
tkHyperlinkManager.HyperlinkManager.__init__" class="py-name" href="#" onclick="return doclink('link-5', '__init__', 'link-5');">__init__</a></tt><tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">,</tt> <tt class="py-name">data_location</tt><tt class="py-op">)</tt> </tt>
<a name="L32"></a><tt class="py-lineno"> 32</tt>  <tt class="py-line">        <tt class="py-comment">#super(experiments,self).__init(self)</tt> </tt>
<a name="L33"></a><tt class="py-lineno"> 33</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">freq</tt> <tt class="py-op">=</tt> <tt class="py-number">500</tt><tt class="py-op">;</tt> </tt>
</div><a name="L34"></a><tt class="py-lineno"> 34</tt>  <tt class="py-line">         </tt>
<a name="L35"></a><tt class="py-lineno"> 35</tt>  <tt class="py-line">     </tt>
<a name="experiments.filterStdSweep"></a><div id="experiments.filterStdSweep-def"><a name="L36"></a><tt class="py-lineno"> 36</tt> <a class="py-toggle" href="#" id="experiments.filterStdSweep-toggle" onclick="return toggle('experiments.filterStdSweep');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="experiments.experiments-class.html#filterStdSweep">filterStdSweep</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">freq</tt><tt class="py-op">,</tt> <tt class="py-param">low</tt><tt class="py-op">,</tt> <tt class="py-param">high</tt><tt class="py-op">,</tt> <tt class="py-param">time</tt> <tt class="py-op">=</tt> <tt class="py-number">5</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments.filterStdSweep-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="experiments.filterStdSweep-expanded"><a name="L37"></a><tt class="py-lineno"> 37</tt>  <tt class="py-line">        <tt class="py-docstring">"""</tt> </tt>
<a name="L38"></a><tt class="py-lineno"> 38</tt>  <tt class="py-line"><tt class="py-docstring">        This method will sweep through the range of standard ids given from low to high.</tt> </tt>
<a name="L39"></a><tt class="py-lineno"> 39</tt>  <tt class="py-line"><tt class="py-docstring">        This will actively filter for 6 ids at a time and sniff for the given amount of</tt> </tt>
<a name="L40"></a><tt class="py-lineno"> 40</tt>  <tt class="py-line"><tt class="py-docstring">        time in seconds. If at least one message is read in then it will go individually</tt> </tt>
<a name="L41"></a><tt class="py-lineno"> 41</tt>  <tt class="py-line"><tt class="py-docstring">        through the 6 ids and sniff only for that id for the given amount of time.</tt> </tt>
<a name="L42"></a><tt class="py-lineno"> 42</tt>  <tt class="py-line"><tt class="py-docstring">        This does not save any sniffed packets.</tt> </tt>
<a name="L43"></a><tt class="py-lineno"> 43</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L44"></a><tt class="py-lineno"> 44</tt>  <tt class="py-line"><tt class="py-docstring">        @type  freq: number</tt> </tt>
<a name="L45"></a><tt class="py-lineno"> 45</tt>  <tt class="py-line"><tt class="py-docstring">        @param freq: The frequency at which the bus is communicating</tt> </tt>
<a name="L46"></a><tt class="py-lineno"> 46</tt>  <tt class="py-line"><tt class="py-docstring">        @type   low: integer</tt> </tt>
<a name="L47"></a><tt class="py-lineno"> 47</tt>  <tt class="py-line"><tt class="py-docstring">        @param  low: The low end of the id sweep</tt> </tt>
<a name="L48"></a><tt class="py-lineno"> 48</tt>  <tt class="py-line"><tt class="py-docstring">        @type  high: integer </tt> </tt>
<a name="L49"></a><tt class="py-lineno"> 49</tt>  <tt class="py-line"><tt class="py-docstring">        @param high: The high end of the id sweep</tt> </tt>
<a name="L50"></a><tt class="py-lineno"> 50</tt>  <tt class="py-line"><tt class="py-docstring">        @type  time: number</tt> </tt>
<a name="L51"></a><tt class="py-lineno"> 51</tt>  <tt class="py-line"><tt class="py-docstring">        @param time: Sniff time for each trial. Default is 5 seconds</tt> </tt>
<a name="L52"></a><tt class="py-lineno"> 52</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L53"></a><tt class="py-lineno"> 53</tt>  <tt class="py-line"><tt class="py-docstring">        @rtype: list of numbers</tt> </tt>
<a name="L54"></a><tt class="py-lineno"> 54</tt>  <tt class="py-line"><tt class="py-docstring">        @return: A list of all IDs found during the sweep.</tt> </tt>
<a name="L55"></a><tt class="py-lineno"> 55</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<a name="L56"></a><tt class="py-lineno"> 56</tt>  <tt class="py-line">        <tt class="py-name">msgIDs</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-op">]</tt> </tt>
<a name="L57"></a><tt class="py-lineno"> 57</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt class="py-name">serInit</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L58"></a><tt class="py-lineno"> 58</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-6" class="py-name" targets="Method GoodFETMCPCAN.GoodFETMCPCAN.MCPsetup()=GoodFETMCPCAN.GoodFETMCPCAN-class.html#MCPsetup"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPsetup" class="py-name" href="#" onclick="return doclink('link-6', 'MCPsetup', 'link-6');">MCPsetup</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L59"></a><tt class="py-lineno"> 59</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-name">low</tt><tt class="py-op">,</tt> <tt class="py-name">high</tt><tt class="py-op">+</tt><tt class="py-number">1</tt><tt class="py-op">,</tt> <tt class="py-number">6</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L60"></a><tt class="py-lineno"> 60</tt>  <tt class="py-line">            <tt class="py-keyword">print</tt> <tt class="py-string">"sniffing id: %d, %d, %d, %d, %d, %d"</tt> <tt class="py-op">%</tt> <tt class="py-op">(</tt><tt class="py-name">i</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">1</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">2</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">3</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">4</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">5</tt><tt class="py-op">)</tt> </tt>
<a name="L61"></a><tt class="py-lineno"> 61</tt>  <tt class="py-line">            <tt class="py-name">comment</tt><tt class="py-op">=</tt> <tt class="py-string">"sweepFilter: "</tt> </tt>
<a name="L62"></a><tt class="py-lineno"> 62</tt>  <tt class="py-line">            <tt class="py-comment">#comment = "sweepFilter_%d_%d_%d_%d_%d_%d" % (i,i+1,i+2,i+3,i+4,i+5)</tt> </tt>
<a name="L63"></a><tt class="py-lineno"> 63</tt>  <tt class="py-line">            <tt class="py-name">description</tt> <tt class="py-op">=</tt> <tt class="py-string">"Running a sweep filer for all the possible standard IDs. This run filters for: %d, %d, %d, %d, %d, %d"</tt> <tt class="py-op">%</tt>\ </tt>
<a name="L64"></a><tt class="py-lineno"> 64</tt>  <tt class="py-line">             <tt class="py-op">(</tt><tt class="py-name">i</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">1</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">2</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">3</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">4</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">5</tt><tt class="py-op">)</tt> </tt>
<a name="L65"></a><tt class="py-lineno"> 65</tt>  <tt class="py-line">            <tt class="py-name">count</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-7" class="py-name" targets="Method GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.sniff()=GoodFETMCPCANCommunication.GoodFETMCPCANCommunication-class.html#sniff,Method mainDisplay.DisplayApp.sniff()=mainDisplay.DisplayApp-class.html#sniff"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.sniff
mainDisplay.DisplayApp.sniff" class="py-name" href="#" onclick="return doclink('link-7', 'sniff', 'link-7');">sniff</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">=</tt><tt class="py-name">freq</tt><tt class="py-op">,</tt> <tt class="py-name">duration</tt> <tt class="py-op">=</tt> <tt class="py-name">time</tt><tt class="py-op">,</tt> <tt class="py-name">description</tt> <tt class="py-op">=</tt> <tt class="py-name">description</tt><tt class="py-op">,</tt><tt class="py-name">comment</tt> <tt class="py-op">=</tt> <tt class="py-name">comment</tt><tt class="py-op">,</tt> <tt class="py-name">standardid</tt> <tt class="py-op">=</tt> \ </tt>
<a name="L66"></a><tt class="py-lineno"> 66</tt>  <tt class="py-line">                               <tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">1</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">2</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">3</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">4</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">5</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L67"></a><tt class="py-lineno"> 67</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">count</tt> <tt class="py-op">!=</tt> <tt class="py-number">0</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L68"></a><tt class="py-lineno"> 68</tt>  <tt class="py-line">                <tt class="py-keyword">for</tt> <tt class="py-name">j</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-name">i</tt><tt class="py-op">,</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">5</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L69"></a><tt class="py-lineno"> 69</tt>  <tt class="py-line">                    <tt class="py-name">comment</tt> <tt class="py-op">=</tt> <tt class="py-string">"sweepFilter: "</tt> </tt>
<a name="L70"></a><tt class="py-lineno"> 70</tt>  <tt class="py-line">                    <tt class="py-comment">#comment = "sweepFilter: %d" % (j)</tt> </tt>
<a name="L71"></a><tt class="py-lineno"> 71</tt>  <tt class="py-line">                    <tt class="py-name">description</tt> <tt class="py-op">=</tt> <tt class="py-string">"Running a sweep filer for all the possible standard IDs. This run filters for: %d "</tt> <tt class="py-op">%</tt> <tt class="py-name">j</tt> </tt>
<a name="L72"></a><tt class="py-lineno"> 72</tt>  <tt class="py-line">                    <tt class="py-name">count</tt> <tt class="py-op">=</tt> \ </tt>
<a name="L73"></a><tt class="py-lineno"> 73</tt>  <tt class="py-line">                    <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-8" class="py-name"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.sniff
mainDisplay.DisplayApp.sniff" class="py-name" href="#" onclick="return doclink('link-8', 'sniff', 'link-7');">sniff</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">=</tt><tt class="py-name">freq</tt><tt class="py-op">,</tt> <tt class="py-name">duration</tt> <tt class="py-op">=</tt> <tt class="py-name">time</tt><tt class="py-op">,</tt> <tt class="py-name">description</tt> <tt class="py-op">=</tt> <tt class="py-name">description</tt><tt class="py-op">,</tt><tt class="py-name">comment</tt> <tt class="py-op">=</tt> <tt class="py-name">comment</tt><tt class="py-op">,</tt> <tt class="py-name">standardid</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">j</tt><tt class="py-op">,</tt> <tt class="py-name">j</tt><tt class="py-op">,</tt> <tt class="py-name">j</tt><tt class="py-op">,</tt> <tt class="py-name">j</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L74"></a><tt class="py-lineno"> 74</tt>  <tt class="py-line">                    <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">count</tt> <tt class="py-op">!=</tt> <tt class="py-number">0</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L75"></a><tt class="py-lineno"> 75</tt>  <tt class="py-line">                        <tt class="py-name">msgIDs</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">j</tt><tt class="py-op">)</tt> </tt>
<a name="L76"></a><tt class="py-lineno"> 76</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">msgIDs</tt> </tt>
</div><a name="L77"></a><tt class="py-lineno"> 77</tt>  <tt class="py-line">     </tt>
<a name="L78"></a><tt class="py-lineno"> 78</tt>  <tt class="py-line">     </tt>
<a name="experiments.sweepRandom"></a><div id="experiments.sweepRandom-def"><a name="L79"></a><tt class="py-lineno"> 79</tt> <a class="py-toggle" href="#" id="experiments.sweepRandom-toggle" onclick="return toggle('experiments.sweepRandom');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="experiments.experiments-class.html#sweepRandom">sweepRandom</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">freq</tt><tt class="py-op">,</tt> <tt class="py-param">number</tt> <tt class="py-op">=</tt> <tt class="py-number">5</tt><tt class="py-op">,</tt> <tt class="py-param">time</tt> <tt class="py-op">=</tt> <tt class="py-number">5</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments.sweepRandom-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="experiments.sweepRandom-expanded"><a name="L80"></a><tt class="py-lineno"> 80</tt>  <tt class="py-line">        <tt class="py-docstring">"""</tt> </tt>
<a name="L81"></a><tt class="py-lineno"> 81</tt>  <tt class="py-line"><tt class="py-docstring">        This method will choose random values to listen out of all the possible standard ids up to</tt> </tt>
<a name="L82"></a><tt class="py-lineno"> 82</tt>  <tt class="py-line"><tt class="py-docstring">        the given number. It will sniff for the given amount of time on each set of ids on the given </tt> </tt>
<a name="L83"></a><tt class="py-lineno"> 83</tt>  <tt class="py-line"><tt class="py-docstring">        frequency. Sniffs in groups of 6 but when at least one message is read in it will go through all</tt> </tt>
<a name="L84"></a><tt class="py-lineno"> 84</tt>  <tt class="py-line"><tt class="py-docstring">        six individually before continuing. This does not save any sniffed packets.</tt> </tt>
<a name="L85"></a><tt class="py-lineno"> 85</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L86"></a><tt class="py-lineno"> 86</tt>  <tt class="py-line"><tt class="py-docstring">        @type  freq: number</tt> </tt>
<a name="L87"></a><tt class="py-lineno"> 87</tt>  <tt class="py-line"><tt class="py-docstring">        @param freq: The frequency at which the bus is communicating</tt> </tt>
<a name="L88"></a><tt class="py-lineno"> 88</tt>  <tt class="py-line"><tt class="py-docstring">        @type  number: integer</tt> </tt>
<a name="L89"></a><tt class="py-lineno"> 89</tt>  <tt class="py-line"><tt class="py-docstring">        @param number: High end of the possible ids. This will define a range from 0</tt> </tt>
<a name="L90"></a><tt class="py-lineno"> 90</tt>  <tt class="py-line"><tt class="py-docstring">                       to number that the ids will be chosen from</tt> </tt>
<a name="L91"></a><tt class="py-lineno"> 91</tt>  <tt class="py-line"><tt class="py-docstring">        @type  time: number</tt> </tt>
<a name="L92"></a><tt class="py-lineno"> 92</tt>  <tt class="py-line"><tt class="py-docstring">        @param time: Sniff time for each trial. Default is 5 seconds</tt> </tt>
<a name="L93"></a><tt class="py-lineno"> 93</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L94"></a><tt class="py-lineno"> 94</tt>  <tt class="py-line"><tt class="py-docstring">        @rtype: list of numbers, list of numbers </tt> </tt>
<a name="L95"></a><tt class="py-lineno"> 95</tt>  <tt class="py-line"><tt class="py-docstring">        @return: A list of all IDs found during the sweep and a list of all the </tt> </tt>
<a name="L96"></a><tt class="py-lineno"> 96</tt>  <tt class="py-line"><tt class="py-docstring">                IDs that were listened for throughout the test</tt> </tt>
<a name="L97"></a><tt class="py-lineno"> 97</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<a name="L98"></a><tt class="py-lineno"> 98</tt>  <tt class="py-line">        <tt class="py-name">msgIDs</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-op">]</tt> <tt class="py-comment">#standard IDs that we have observed during run</tt> </tt>
<a name="L99"></a><tt class="py-lineno"> 99</tt>  <tt class="py-line">        <tt class="py-name">ids</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-op">]</tt> <tt class="py-comment">#standard IDs that have been tried</tt> </tt>
<a name="L100"></a><tt class="py-lineno">100</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt class="py-name">serInit</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L101"></a><tt class="py-lineno">101</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-9" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPsetup" class="py-name" href="#" onclick="return doclink('link-9', 'MCPsetup', 'link-6');">MCPsetup</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L102"></a><tt class="py-lineno">102</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-name">number</tt><tt class="py-op">+</tt><tt class="py-number">1</tt><tt class="py-op">,</tt><tt class="py-number">6</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L103"></a><tt class="py-lineno">103</tt>  <tt class="py-line">            <tt class="py-name">idsTemp</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-op">]</tt> </tt>
<a name="L104"></a><tt class="py-lineno">104</tt>  <tt class="py-line">            <tt class="py-name">comment</tt> <tt class="py-op">=</tt> <tt class="py-string">"sweepFilter: "</tt> </tt>
<a name="L105"></a><tt class="py-lineno">105</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">j</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">6</tt><tt class="py-op">,</tt><tt class="py-number">1</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L106"></a><tt class="py-lineno">106</tt>  <tt class="py-line">                <tt class="py-name">id</tt> <tt class="py-op">=</tt> <tt class="py-name">randrange</tt><tt class="py-op">(</tt><tt class="py-number">2047</tt><tt class="py-op">)</tt> </tt>
<a name="L107"></a><tt class="py-lineno">107</tt>  <tt class="py-line">                <tt class="py-comment">#comment += "_%d" % id</tt> </tt>
<a name="L108"></a><tt class="py-lineno">108</tt>  <tt class="py-line">                <tt class="py-name">idsTemp</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">id</tt><tt class="py-op">)</tt> </tt>
<a name="L109"></a><tt class="py-lineno">109</tt>  <tt class="py-line">                <tt class="py-name">ids</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">id</tt><tt class="py-op">)</tt> </tt>
<a name="L110"></a><tt class="py-lineno">110</tt>  <tt class="py-line">            <tt class="py-comment">#print comment</tt> </tt>
<a name="L111"></a><tt class="py-lineno">111</tt>  <tt class="py-line">            <tt class="py-name">description</tt> <tt class="py-op">=</tt> <tt class="py-string">"Running a sweep filer for all the possible standard IDs. This runs the following : "</tt> \ </tt>
<a name="L112"></a><tt class="py-lineno">112</tt>  <tt class="py-line">                                                                                                        <tt class="py-op">+</tt> <tt class="py-name">comment</tt> </tt>
<a name="L113"></a><tt class="py-lineno">113</tt>  <tt class="py-line">            <tt class="py-name">count</tt> <tt class="py-op">=</tt> \ </tt>
<a name="L114"></a><tt class="py-lineno">114</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-10" class="py-name"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.sniff
mainDisplay.DisplayApp.sniff" class="py-name" href="#" onclick="return doclink('link-10', 'sniff', 'link-7');">sniff</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">=</tt><tt class="py-name">freq</tt><tt class="py-op">,</tt> <tt class="py-name">duration</tt><tt class="py-op">=</tt><tt class="py-name">time</tt><tt class="py-op">,</tt> <tt class="py-name">description</tt><tt class="py-op">=</tt><tt class="py-name">description</tt><tt class="py-op">,</tt> <tt class="py-name">comment</tt> <tt class="py-op">=</tt> <tt class="py-name">comment</tt><tt class="py-op">,</tt> <tt class="py-name">standardid</tt> <tt class="py-op">=</tt> <tt class="py-name">idsTemp</tt><tt class="py-op">)</tt> </tt>
<a name="L115"></a><tt class="py-lineno">115</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">count</tt> <tt class="py-op">!=</tt> <tt class="py-number">0</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L116"></a><tt class="py-lineno">116</tt>  <tt class="py-line">                <tt class="py-keyword">for</tt> <tt class="py-name">element</tt> <tt class="py-keyword">in</tt> <tt class="py-name">idsTemp</tt><tt class="py-op">:</tt> </tt>
<a name="L117"></a><tt class="py-lineno">117</tt>  <tt class="py-line">                    <tt class="py-comment">#comment = "sweepFilter: %d" % (element)</tt> </tt>
<a name="L118"></a><tt class="py-lineno">118</tt>  <tt class="py-line">                    <tt class="py-name">comment</tt><tt class="py-op">=</tt><tt class="py-string">"sweepFilter: "</tt> </tt>
<a name="L119"></a><tt class="py-lineno">119</tt>  <tt class="py-line">                    <tt class="py-name">description</tt> <tt class="py-op">=</tt> <tt class="py-string">"Running a sweep filer for all the possible standard IDs. This run filters for: %d "</tt> \ </tt>
<a name="L120"></a><tt class="py-lineno">120</tt>  <tt class="py-line">                                                                                                                <tt class="py-op">%</tt> <tt class="py-name">element</tt> </tt>
<a name="L121"></a><tt class="py-lineno">121</tt>  <tt class="py-line">                    <tt class="py-name">count</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-11" class="py-name"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.sniff
mainDisplay.DisplayApp.sniff" class="py-name" href="#" onclick="return doclink('link-11', 'sniff', 'link-7');">sniff</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">=</tt><tt class="py-name">freq</tt><tt class="py-op">,</tt> <tt class="py-name">duration</tt> <tt class="py-op">=</tt> <tt class="py-name">time</tt><tt class="py-op">,</tt> <tt class="py-name">description</tt> <tt class="py-op">=</tt> <tt class="py-name">description</tt><tt class="py-op">,</tt><tt class="py-name">comment</tt> <tt class="py-op">=</tt> <tt class="py-name">comment</tt><tt class="py-op">,</tt> <tt class="py-name">standardid</tt> <tt class="py-op">=</tt>\ </tt>
<a name="L122"></a><tt class="py-lineno">122</tt>  <tt class="py-line">                                                                                             <tt class="py-op">[</tt><tt class="py-name">element</tt><tt class="py-op">,</tt> <tt class="py-name">element</tt><tt class="py-op">,</tt> <tt class="py-name">element</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L123"></a><tt class="py-lineno">123</tt>  <tt class="py-line">                    <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">count</tt> <tt class="py-op">!=</tt> <tt class="py-number">0</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L124"></a><tt class="py-lineno">124</tt>  <tt class="py-line">                        <tt class="py-name">msgIDs</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">j</tt><tt class="py-op">)</tt> </tt>
<a name="L125"></a><tt class="py-lineno">125</tt>  <tt class="py-line">        <tt class="py-keyword">return</tt> <tt class="py-name">msgIDs</tt><tt class="py-op">,</tt> <tt class="py-name">ids</tt> </tt>
</div><a name="L126"></a><tt class="py-lineno">126</tt>  <tt class="py-line">     </tt>
<a name="L127"></a><tt class="py-lineno">127</tt>  <tt class="py-line">     </tt>
<a name="experiments.rtrSweep"></a><div id="experiments.rtrSweep-def"><a name="L128"></a><tt class="py-lineno">128</tt> <a class="py-toggle" href="#" id="experiments.rtrSweep-toggle" onclick="return toggle('experiments.rtrSweep');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="experiments.experiments-class.html#rtrSweep">rtrSweep</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt><tt class="py-param">freq</tt><tt class="py-op">,</tt><tt class="py-param">lowID</tt><tt class="py-op">,</tt><tt class="py-param">highID</tt><tt class="py-op">,</tt> <tt class="py-param">attempts</tt> <tt class="py-op">=</tt> <tt class="py-number">1</tt><tt class="py-op">,</tt><tt class="py-param">duration</tt> <tt class="py-op">=</tt> <tt class="py-number">1</tt><tt class="py-op">,</tt> <tt class="py-param">verbose</tt> <tt class="py-op">=</tt> <tt class="py-name">True</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments.rtrSweep-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="experiments.rtrSweep-expanded"><a name="L129"></a><tt class="py-lineno">129</tt>  <tt class="py-line">        <tt class="py-docstring">"""</tt> </tt>
<a name="L130"></a><tt class="py-lineno">130</tt>  <tt class="py-line"><tt class="py-docstring">        This method will sweep through the range of ids given by lowID to highID and</tt> </tt>
<a name="L131"></a><tt class="py-lineno">131</tt>  <tt class="py-line"><tt class="py-docstring">        send a remote transmissions request (RTR) to each id and then listen for a response. </tt> </tt>
<a name="L132"></a><tt class="py-lineno">132</tt>  <tt class="py-line"><tt class="py-docstring">        The RTR will be repeated in the given number of attempts and will sniff for the given duration</tt> </tt>
<a name="L133"></a><tt class="py-lineno">133</tt>  <tt class="py-line"><tt class="py-docstring">        continuing to the next id.</tt> </tt>
<a name="L134"></a><tt class="py-lineno">134</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L135"></a><tt class="py-lineno">135</tt>  <tt class="py-line"><tt class="py-docstring">        Any messages that are sniffed will be saved to a csv file. </tt> </tt>
<a name="L136"></a><tt class="py-lineno">136</tt>  <tt class="py-line"><tt class="py-docstring">        The filename will be stored in the DATA_LOCATION folder</tt> </tt>
<a name="L137"></a><tt class="py-lineno">137</tt>  <tt class="py-line"><tt class="py-docstring">        with a filename that is the date (YYYYMMDD)_rtr.csv. </tt> </tt>
<a name="L138"></a><tt class="py-lineno">138</tt>  <tt class="py-line"><tt class="py-docstring">        If the file already exists it will append to the end of the file</tt> </tt>
<a name="L139"></a><tt class="py-lineno">139</tt>  <tt class="py-line"><tt class="py-docstring">        The format will follow that of L{GoodFETMCPCANCommunication.sniff} </tt> </tt>
<a name="L140"></a><tt class="py-lineno">140</tt>  <tt class="py-line"><tt class="py-docstring">        in that the columns will be as follows::</tt> </tt>
<a name="L141"></a><tt class="py-lineno">141</tt>  <tt class="py-line"><tt class="py-docstring">            1. timestamp:     as floating point number</tt> </tt>
<a name="L142"></a><tt class="py-lineno">142</tt>  <tt class="py-line"><tt class="py-docstring">            2. error boolean: 1 if there was an error detected of packet formatting (not exhaustive check). 0 otherwise</tt> </tt>
<a name="L143"></a><tt class="py-lineno">143</tt>  <tt class="py-line"><tt class="py-docstring">            3. comment tag:   comment about experiments as String</tt> </tt>
<a name="L144"></a><tt class="py-lineno">144</tt>  <tt class="py-line"><tt class="py-docstring">            4. duration:      Length of overall sniff</tt> </tt>
<a name="L145"></a><tt class="py-lineno">145</tt>  <tt class="py-line"><tt class="py-docstring">            5. filtering:     1 if there was filtering. 0 otherwise</tt> </tt>
<a name="L146"></a><tt class="py-lineno">146</tt>  <tt class="py-line"><tt class="py-docstring">            6. db0:           Integer</tt> </tt>
<a name="L147"></a><tt class="py-lineno">147</tt>  <tt class="py-line"><tt class="py-docstring">            </tt> </tt>
<a name="L148"></a><tt class="py-lineno">148</tt>  <tt class="py-line"><tt class="py-docstring">                ---</tt> </tt>
<a name="L149"></a><tt class="py-lineno">149</tt>  <tt class="py-line"><tt class="py-docstring">            7. db7:           Integer</tt> </tt>
<a name="L150"></a><tt class="py-lineno">150</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L151"></a><tt class="py-lineno">151</tt>  <tt class="py-line"><tt class="py-docstring">        @type  freq: number</tt> </tt>
<a name="L152"></a><tt class="py-lineno">152</tt>  <tt class="py-line"><tt class="py-docstring">        @param freq: The frequency at which the bus is communicating</tt> </tt>
<a name="L153"></a><tt class="py-lineno">153</tt>  <tt class="py-line"><tt class="py-docstring">        @type   lowID: integer</tt> </tt>
<a name="L154"></a><tt class="py-lineno">154</tt>  <tt class="py-line"><tt class="py-docstring">        @param  lowID: The low end of the id sweep</tt> </tt>
<a name="L155"></a><tt class="py-lineno">155</tt>  <tt class="py-line"><tt class="py-docstring">        @type  highID: integer </tt> </tt>
<a name="L156"></a><tt class="py-lineno">156</tt>  <tt class="py-line"><tt class="py-docstring">        @param highID: The high end of the id sweep</tt> </tt>
<a name="L157"></a><tt class="py-lineno">157</tt>  <tt class="py-line"><tt class="py-docstring">        @type attempts: integer</tt> </tt>
<a name="L158"></a><tt class="py-lineno">158</tt>  <tt class="py-line"><tt class="py-docstring">        @param attempts: The number of times a RTR will be repeated for a given standard id</tt> </tt>
<a name="L159"></a><tt class="py-lineno">159</tt>  <tt class="py-line"><tt class="py-docstring">        @type  duration: integer</tt> </tt>
<a name="L160"></a><tt class="py-lineno">160</tt>  <tt class="py-line"><tt class="py-docstring">        @param duration: The length of time that it will listen to the bus after sending an RTR</tt> </tt>
<a name="L161"></a><tt class="py-lineno">161</tt>  <tt class="py-line"><tt class="py-docstring">        @type verbose:  boolean</tt> </tt>
<a name="L162"></a><tt class="py-lineno">162</tt>  <tt class="py-line"><tt class="py-docstring">        @param verbose: When true, messages will be printed out to the terminal</tt> </tt>
<a name="L163"></a><tt class="py-lineno">163</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L164"></a><tt class="py-lineno">164</tt>  <tt class="py-line"><tt class="py-docstring">        @rtype: None</tt> </tt>
<a name="L165"></a><tt class="py-lineno">165</tt>  <tt class="py-line"><tt class="py-docstring">        @return: Does not return anything</tt> </tt>
<a name="L166"></a><tt class="py-lineno">166</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<a name="L167"></a><tt class="py-lineno">167</tt>  <tt class="py-line">        <tt class="py-comment">#set up file for writing</tt> </tt>
<a name="L168"></a><tt class="py-lineno">168</tt>  <tt class="py-line">        <tt class="py-name">now</tt> <tt class="py-op">=</tt> <tt class="py-name">datetime</tt><tt class="py-op">.</tt><tt class="py-name">datetime</tt><tt class="py-op">.</tt><tt class="py-name">now</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L169"></a><tt class="py-lineno">169</tt>  <tt class="py-line">        <tt class="py-name">datestr</tt> <tt class="py-op">=</tt> <tt class="py-name">now</tt><tt class="py-op">.</tt><tt class="py-name">strftime</tt><tt class="py-op">(</tt><tt class="py-string">"%Y%m%d"</tt><tt class="py-op">)</tt> </tt>
<a name="L170"></a><tt class="py-lineno">170</tt>  <tt class="py-line">        <tt class="py-name">path</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">DATA_LOCATION</tt><tt class="py-op">+</tt><tt class="py-name">datestr</tt><tt class="py-op">+</tt><tt class="py-string">"_rtr.csv"</tt> </tt>
<a name="L171"></a><tt class="py-lineno">171</tt>  <tt class="py-line">        <tt class="py-name">filename</tt> <tt class="py-op">=</tt> <tt class="py-name">path</tt> </tt>
<a name="L172"></a><tt class="py-lineno">172</tt>  <tt class="py-line">        <tt class="py-name">outfile</tt> <tt class="py-op">=</tt> <tt class="py-name">open</tt><tt class="py-op">(</tt><tt class="py-name">filename</tt><tt class="py-op">,</tt><tt class="py-string">'a'</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L173"></a><tt class="py-lineno">173</tt>  <tt class="py-line">        <tt class="py-name">dataWriter</tt> <tt class="py-op">=</tt> <tt class="py-name">csv</tt><tt class="py-op">.</tt><tt class="py-name">writer</tt><tt class="py-op">(</tt><tt class="py-name">outfile</tt><tt class="py-op">,</tt><tt class="py-name">delimiter</tt><tt class="py-op">=</tt><tt class="py-string">','</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L174"></a><tt class="py-lineno">174</tt>  <tt class="py-line">        <tt class="py-name">dataWriter</tt><tt class="py-op">.</tt><tt class="py-name">writerow</tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-string">'# Time     Error        Bytes 1-13'</tt><tt class="py-op">]</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L175"></a><tt class="py-lineno">175</tt>  <tt class="py-line">        <tt class="py-name">dataWriter</tt><tt class="py-op">.</tt><tt class="py-name">writerow</tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-string">'#'</tt> <tt class="py-op">+</tt> <tt class="py-string">"rtr sweep from %d to %d"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">lowID</tt><tt class="py-op">,</tt><tt class="py-name">highID</tt><tt class="py-op">)</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L176"></a><tt class="py-lineno">176</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">verbose</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L177"></a><tt class="py-lineno">177</tt>  <tt class="py-line">            <tt class="py-keyword">print</tt> <tt class="py-string">"started"</tt> </tt>
<a name="L178"></a><tt class="py-lineno">178</tt>  <tt class="py-line">        <tt class="py-comment">#self.client.serInit()</tt> </tt>
<a name="L179"></a><tt class="py-lineno">179</tt>  <tt class="py-line">        <tt class="py-comment">#self.spitSetup(freq)</tt> </tt>
<a name="L180"></a><tt class="py-lineno">180</tt>  <tt class="py-line">         </tt>
<a name="L181"></a><tt class="py-lineno">181</tt>  <tt class="py-line">        <tt class="py-comment">#for each id</tt> </tt>
<a name="L182"></a><tt class="py-lineno">182</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-name">lowID</tt><tt class="py-op">,</tt><tt class="py-name">highID</tt><tt class="py-op">+</tt><tt class="py-number">1</tt><tt class="py-op">,</tt> <tt class="py-number">1</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L183"></a><tt class="py-lineno">183</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt class="py-name">serInit</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L184"></a><tt class="py-lineno">184</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-12" class="py-name" targets="Method GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.spitSetup()=GoodFETMCPCANCommunication.GoodFETMCPCANCommunication-class.html#spitSetup"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.spitSetup" class="py-name" href="#" onclick="return doclink('link-12', 'spitSetup', 'link-12');">spitSetup</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">)</tt> <tt class="py-comment">#reset the chip to try and avoid serial timeouts</tt> </tt>
<a name="L185"></a><tt class="py-lineno">185</tt>  <tt class="py-line">            <tt class="py-comment">#set filters</tt> </tt>
<a name="L186"></a><tt class="py-lineno">186</tt>  <tt class="py-line">            <tt class="py-name">standardid</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">,</tt> <tt class="py-name">i</tt><tt class="py-op">]</tt> </tt>
<a name="L187"></a><tt class="py-lineno">187</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-13" class="py-name" targets="Method GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.addFilter()=GoodFETMCPCANCommunication.GoodFETMCPCANCommunication-class.html#addFilter"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.addFilter" class="py-name" href="#" onclick="return doclink('link-13', 'addFilter', 'link-13');">addFilter</a></tt><tt class="py-op">(</tt><tt class="py-name">standardid</tt><tt class="py-op">,</tt> <tt class="py-name">verbose</tt> <tt class="py-op">=</tt> <tt class="py-name">True</tt><tt class="py-op">)</tt> </tt>
<a name="L188"></a><tt class="py-lineno">188</tt>  <tt class="py-line">             </tt>
<a name="L189"></a><tt class="py-lineno">189</tt>  <tt class="py-line">            <tt class="py-comment">#### split SID into different areas</tt> </tt>
<a name="L190"></a><tt class="py-lineno">190</tt>  <tt class="py-line">            <tt class="py-name">SIDlow</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">standardid</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0x07</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;&lt;</tt> <tt class="py-number">5</tt><tt class="py-op">;</tt>  <tt class="py-comment"># get SID bits 2:0, rotate them to bits 7:5</tt> </tt>
<a name="L191"></a><tt class="py-lineno">191</tt>  <tt class="py-line">            <tt class="py-name">SIDhigh</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">standardid</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> <tt class="py-op">&gt;&gt;</tt> <tt class="py-number">3</tt><tt class="py-op">)</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0xFF</tt><tt class="py-op">;</tt> <tt class="py-comment"># get SID bits 10:3, rotate them to bits 7:0</tt> </tt>
<a name="L192"></a><tt class="py-lineno">192</tt>  <tt class="py-line">            <tt class="py-comment">#create RTR packet</tt> </tt>
<a name="L193"></a><tt class="py-lineno">193</tt>  <tt class="py-line">            <tt class="py-name">packet</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">SIDhigh</tt><tt class="py-op">,</tt> <tt class="py-name">SIDlow</tt><tt class="py-op">,</tt> <tt class="py-number">0x00</tt><tt class="py-op">,</tt><tt class="py-number">0x00</tt><tt class="py-op">,</tt><tt class="py-number">0x40</tt><tt class="py-op">]</tt> </tt>
<a name="L194"></a><tt class="py-lineno">194</tt>  <tt class="py-line">            <tt class="py-name">dataWriter</tt><tt class="py-op">.</tt><tt class="py-name">writerow</tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-string">"#requested id %d"</tt><tt class="py-op">%</tt><tt class="py-name">i</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L195"></a><tt class="py-lineno">195</tt>  <tt class="py-line">            <tt class="py-comment">#clear buffer</tt> </tt>
<a name="L196"></a><tt class="py-lineno">196</tt>  <tt class="py-line">            <tt class="py-name">packet1</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-14" class="py-name" targets="Method GoodFETMCPCAN.GoodFETMCPCAN.rxpacket()=GoodFETMCPCAN.GoodFETMCPCAN-class.html#rxpacket"><a title="GoodFETMCPCAN.GoodFETMCPCAN.rxpacket" class="py-name" href="#" onclick="return doclink('link-14', 'rxpacket', 'link-14');">rxpacket</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L197"></a><tt class="py-lineno">197</tt>  <tt class="py-line">            <tt class="py-name">packet2</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-15" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.rxpacket" class="py-name" href="#" onclick="return doclink('link-15', 'rxpacket', 'link-14');">rxpacket</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L198"></a><tt class="py-lineno">198</tt>  <tt class="py-line">            <tt class="py-comment">#send in rtr request</tt> </tt>
<a name="L199"></a><tt class="py-lineno">199</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-16" class="py-name" targets="Method GoodFETMCPCAN.GoodFETMCPCAN.txpacket()=GoodFETMCPCAN.GoodFETMCPCAN-class.html#txpacket"><a title="GoodFETMCPCAN.GoodFETMCPCAN.txpacket" class="py-name" href="#" onclick="return doclink('link-16', 'txpacket', 'link-16');">txpacket</a></tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">)</tt> </tt>
<a name="L200"></a><tt class="py-lineno">200</tt>  <tt class="py-line">            <tt class="py-comment">## listen for 2 packets. one should be the rtr we requested the other should be</tt> </tt>
<a name="L201"></a><tt class="py-lineno">201</tt>  <tt class="py-line">            <tt class="py-comment">## a new packet response</tt> </tt>
<a name="L202"></a><tt class="py-lineno">202</tt>  <tt class="py-line">            <tt class="py-name">starttime</tt> <tt class="py-op">=</tt> <tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L203"></a><tt class="py-lineno">203</tt>  <tt class="py-line">            <tt class="py-keyword">while</tt> <tt class="py-op">(</tt><tt class="py-op">(</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-op">-</tt> <tt class="py-name">starttime</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;</tt> <tt class="py-name">duration</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> <tt class="py-comment">#listen for the given duration time period</tt> </tt>
<a name="L204"></a><tt class="py-lineno">204</tt>  <tt class="py-line">                <tt class="py-name">packet</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-17" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.rxpacket" class="py-name" href="#" onclick="return doclink('link-17', 'rxpacket', 'link-14');">rxpacket</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L205"></a><tt class="py-lineno">205</tt>  <tt class="py-line">                <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">packet</tt> <tt class="py-op">==</tt> <tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L206"></a><tt class="py-lineno">206</tt>  <tt class="py-line">                    <tt class="py-keyword">continue</tt> </tt>
<a name="L207"></a><tt class="py-lineno">207</tt>  <tt class="py-line">                <tt class="py-comment"># we have sniffed a packet, save it</tt> </tt>
<a name="L208"></a><tt class="py-lineno">208</tt>  <tt class="py-line">                <tt class="py-name">row</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-op">]</tt> </tt>
<a name="L209"></a><tt class="py-lineno">209</tt>  <tt class="py-line">                <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-string">"%f"</tt><tt class="py-op">%</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> <tt class="py-comment">#timestamp</tt> </tt>
<a name="L210"></a><tt class="py-lineno">210</tt>  <tt class="py-line">                <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">)</tt> <tt class="py-comment">#error flag (not checkign)</tt> </tt>
<a name="L211"></a><tt class="py-lineno">211</tt>  <tt class="py-line">                <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-string">"rtrRequest_%d"</tt><tt class="py-op">%</tt><tt class="py-name">i</tt><tt class="py-op">)</tt> <tt class="py-comment">#comment</tt> </tt>
<a name="L212"></a><tt class="py-lineno">212</tt>  <tt class="py-line">                <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">duration</tt><tt class="py-op">)</tt> <tt class="py-comment">#sniff time</tt> </tt>
<a name="L213"></a><tt class="py-lineno">213</tt>  <tt class="py-line">                <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-number">1</tt><tt class="py-op">)</tt> <tt class="py-comment"># filtering boolean</tt> </tt>
<a name="L214"></a><tt class="py-lineno">214</tt>  <tt class="py-line">                <tt class="py-keyword">for</tt> <tt class="py-name">byte</tt> <tt class="py-keyword">in</tt> <tt class="py-name">packet</tt><tt class="py-op">:</tt> </tt>
<a name="L215"></a><tt class="py-lineno">215</tt>  <tt class="py-line">                    <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-string">"%02x"</tt><tt class="py-op">%</tt><tt class="py-name">ord</tt><tt class="py-op">(</tt><tt class="py-name">byte</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L216"></a><tt class="py-lineno">216</tt>  <tt class="py-line">                <tt class="py-name">dataWriter</tt><tt class="py-op">.</tt><tt class="py-name">writerow</tt><tt class="py-op">(</tt><tt class="py-name">row</tt><tt class="py-op">)</tt> </tt>
<a name="L217"></a><tt class="py-lineno">217</tt>  <tt class="py-line">                <tt class="py-keyword">print</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-18" class="py-name" targets="Method GoodFETMCPCAN.GoodFETMCPCAN.packet2parsedstr()=GoodFETMCPCAN.GoodFETMCPCAN-class.html#packet2parsedstr"><a title="GoodFETMCPCAN.GoodFETMCPCAN.packet2parsedstr" class="py-name" href="#" onclick="return doclink('link-18', 'packet2parsedstr', 'link-18');">packet2parsedstr</a></tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">)</tt> </tt>
<a name="L218"></a><tt class="py-lineno">218</tt>  <tt class="py-line">            <tt class="py-name">trial</tt><tt class="py-op">=</tt> <tt class="py-number">2</tt><tt class="py-op">;</tt> </tt>
<a name="L219"></a><tt class="py-lineno">219</tt>  <tt class="py-line">            <tt class="py-comment"># for each trial repeat</tt> </tt>
<a name="L220"></a><tt class="py-lineno">220</tt>  <tt class="py-line">            <tt class="py-keyword">while</tt><tt class="py-op">(</tt> <tt class="py-name">trial</tt> <tt class="py-op">&lt;=</tt> <tt class="py-name">attempts</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L221"></a><tt class="py-lineno">221</tt>  <tt class="py-line">                <tt class="py-keyword">print</tt> <tt class="py-string">"trial: "</tt><tt class="py-op">,</tt> <tt class="py-name">trial</tt> </tt>
<a name="L222"></a><tt class="py-lineno">222</tt>  <tt class="py-line">                <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-19" class="py-name" targets="Method GoodFETMCPCAN.GoodFETMCPCAN.MCPrts()=GoodFETMCPCAN.GoodFETMCPCAN-class.html#MCPrts"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPrts" class="py-name" href="#" onclick="return doclink('link-19', 'MCPrts', 'link-19');">MCPrts</a></tt><tt class="py-op">(</tt><tt class="py-name">TXB0</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L223"></a><tt class="py-lineno">223</tt>  <tt class="py-line">                <tt class="py-name">starttime</tt> <tt class="py-op">=</tt> <tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L224"></a><tt class="py-lineno">224</tt>  <tt class="py-line">                <tt class="py-comment"># this time we will sniff for the given amount of time to see if there is a</tt> </tt>
<a name="L225"></a><tt class="py-lineno">225</tt>  <tt class="py-line">                <tt class="py-comment"># time till the packets come in</tt> </tt>
<a name="L226"></a><tt class="py-lineno">226</tt>  <tt class="py-line">                <tt class="py-keyword">while</tt><tt class="py-op">(</tt> <tt class="py-op">(</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">-</tt><tt class="py-name">starttime</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;</tt> <tt class="py-name">duration</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L227"></a><tt class="py-lineno">227</tt>  <tt class="py-line">                    <tt class="py-name">packet</tt><tt class="py-op">=</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-20" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.rxpacket" class="py-name" href="#" onclick="return doclink('link-20', 'rxpacket', 'link-14');">rxpacket</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L228"></a><tt class="py-lineno">228</tt>  <tt class="py-line">                    <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">packet</tt> <tt class="py-op">==</tt> <tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L229"></a><tt class="py-lineno">229</tt>  <tt class="py-line">                        <tt class="py-keyword">continue</tt> </tt>
<a name="L230"></a><tt class="py-lineno">230</tt>  <tt class="py-line">                    <tt class="py-name">row</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-op">]</tt> </tt>
<a name="L231"></a><tt class="py-lineno">231</tt>  <tt class="py-line">                    <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-string">"%f"</tt><tt class="py-op">%</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> <tt class="py-comment">#timestamp</tt> </tt>
<a name="L232"></a><tt class="py-lineno">232</tt>  <tt class="py-line">                    <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">)</tt> <tt class="py-comment">#error flag (not checking)</tt> </tt>
<a name="L233"></a><tt class="py-lineno">233</tt>  <tt class="py-line">                    <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-string">"rtrRequest_%d"</tt><tt class="py-op">%</tt><tt class="py-name">i</tt><tt class="py-op">)</tt> <tt class="py-comment">#comment</tt> </tt>
<a name="L234"></a><tt class="py-lineno">234</tt>  <tt class="py-line">                    <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">duration</tt><tt class="py-op">)</tt> <tt class="py-comment">#sniff time</tt> </tt>
<a name="L235"></a><tt class="py-lineno">235</tt>  <tt class="py-line">                    <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-number">1</tt><tt class="py-op">)</tt> <tt class="py-comment"># filtering boolean</tt> </tt>
<a name="L236"></a><tt class="py-lineno">236</tt>  <tt class="py-line">                    <tt class="py-keyword">for</tt> <tt class="py-name">byte</tt> <tt class="py-keyword">in</tt> <tt class="py-name">packet</tt><tt class="py-op">:</tt> </tt>
<a name="L237"></a><tt class="py-lineno">237</tt>  <tt class="py-line">                        <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-string">"%02x"</tt><tt class="py-op">%</tt><tt class="py-name">ord</tt><tt class="py-op">(</tt><tt class="py-name">byte</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L238"></a><tt class="py-lineno">238</tt>  <tt class="py-line">                    <tt class="py-name">dataWriter</tt><tt class="py-op">.</tt><tt class="py-name">writerow</tt><tt class="py-op">(</tt><tt class="py-name">row</tt><tt class="py-op">)</tt> </tt>
<a name="L239"></a><tt class="py-lineno">239</tt>  <tt class="py-line">                    <tt class="py-keyword">print</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-21" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.packet2parsedstr" class="py-name" href="#" onclick="return doclink('link-21', 'packet2parsedstr', 'link-18');">packet2parsedstr</a></tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">)</tt> </tt>
<a name="L240"></a><tt class="py-lineno">240</tt>  <tt class="py-line">                <tt class="py-name">trial</tt> <tt class="py-op">+=</tt> <tt class="py-number">1</tt> </tt>
<a name="L241"></a><tt class="py-lineno">241</tt>  <tt class="py-line">        <tt class="py-keyword">print</tt> <tt class="py-string">"sweep complete"</tt> </tt>
<a name="L242"></a><tt class="py-lineno">242</tt>  <tt class="py-line">        <tt class="py-name">outfile</tt><tt class="py-op">.</tt><tt class="py-name">close</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
</div><a name="L243"></a><tt class="py-lineno">243</tt>  <tt class="py-line">         </tt>
<a name="L244"></a><tt class="py-lineno">244</tt>  <tt class="py-line">    <tt class="py-comment"># This method will do generation based fuzzing on the id given in standard id</tt> </tt>
<a name="L245"></a><tt class="py-lineno">245</tt>  <tt class="py-line">    <tt class="py-comment"># dbLimits is a dictionary of the databytes</tt> </tt>
<a name="L246"></a><tt class="py-lineno">246</tt>  <tt class="py-line">    <tt class="py-comment"># dbLimits['db0'] = [low, High]</tt> </tt>
<a name="L247"></a><tt class="py-lineno">247</tt>  <tt class="py-line">    <tt class="py-comment"># ..</tt> </tt>
<a name="L248"></a><tt class="py-lineno">248</tt>  <tt class="py-line">    <tt class="py-comment"># dbLimits['db7'] = [low, High]</tt> </tt>
<a name="L249"></a><tt class="py-lineno">249</tt>  <tt class="py-line">    <tt class="py-comment"># where low is the low end of values for the fuzz, high is the high end value</tt> </tt>
<a name="L250"></a><tt class="py-lineno">250</tt>  <tt class="py-line">    <tt class="py-comment"># period is the time between sending packets in milliseconds, writesPerFuzz is the times the </tt> </tt>
<a name="L251"></a><tt class="py-lineno">251</tt>  <tt class="py-line">    <tt class="py-comment"># same fuzzed packet will be injecetez. Fuzzes is the number of different packets to be injected</tt> </tt>
<a name="experiments.generationFuzzer"></a><div id="experiments.generationFuzzer-def"><a name="L252"></a><tt class="py-lineno">252</tt> <a class="py-toggle" href="#" id="experiments.generationFuzzer-toggle" onclick="return toggle('experiments.generationFuzzer');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="experiments.experiments-class.html#generationFuzzer">generationFuzzer</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt><tt class="py-param">freq</tt><tt class="py-op">,</tt> <tt class="py-param">standardIDs</tt><tt class="py-op">,</tt> <tt class="py-param">dbLimits</tt><tt class="py-op">,</tt> <tt class="py-param">period</tt><tt class="py-op">,</tt> <tt class="py-param">writesPerFuzz</tt><tt class="py-op">,</tt> <tt class="py-param">Fuzzes</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments.generationFuzzer-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="experiments.generationFuzzer-expanded"><a name="L253"></a><tt class="py-lineno">253</tt>  <tt class="py-line">        <tt class="py-docstring">"""</tt> </tt>
<a name="L254"></a><tt class="py-lineno">254</tt>  <tt class="py-line"><tt class="py-docstring">        This method will perform generation based fuzzing on the bus. The method will inject</tt> </tt>
<a name="L255"></a><tt class="py-lineno">255</tt>  <tt class="py-line"><tt class="py-docstring">        properly formatted, randomly generated messages at a given period for a I{writesPerFuzz} </tt> </tt>
<a name="L256"></a><tt class="py-lineno">256</tt>  <tt class="py-line"><tt class="py-docstring">        number of times. The packets that are injected into the bus will all be saved in the following path</tt> </tt>
<a name="L257"></a><tt class="py-lineno">257</tt>  <tt class="py-line"><tt class="py-docstring">        DATALOCATION/InjectedData/(today's date (YYYYMMDD))_GenerationFuzzedPackets.csv.</tt> </tt>
<a name="L258"></a><tt class="py-lineno">258</tt>  <tt class="py-line"><tt class="py-docstring">        An example filename would be 20130222_GenerationFuzzedPackets.csv</tt> </tt>
<a name="L259"></a><tt class="py-lineno">259</tt>  <tt class="py-line"><tt class="py-docstring">        Where DATALOCATION is provided when the class is initiated. The data will be saved as integers.</tt> </tt>
<a name="L260"></a><tt class="py-lineno">260</tt>  <tt class="py-line"><tt class="py-docstring">        Each row will be formatted in the following form::</tt> </tt>
<a name="L261"></a><tt class="py-lineno">261</tt>  <tt class="py-line"><tt class="py-docstring">                     row = [time of injection, standardID, 8, db0, db1, db2, db3, db4, db5, db6, db7]</tt> </tt>
<a name="L262"></a><tt class="py-lineno">262</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L263"></a><tt class="py-lineno">263</tt>  <tt class="py-line"><tt class="py-docstring">        @type  freq: number</tt> </tt>
<a name="L264"></a><tt class="py-lineno">264</tt>  <tt class="py-line"><tt class="py-docstring">        @param freq: The frequency at which the bus is communicating</tt> </tt>
<a name="L265"></a><tt class="py-lineno">265</tt>  <tt class="py-line"><tt class="py-docstring">        @type standardIDs: list of integers</tt> </tt>
<a name="L266"></a><tt class="py-lineno">266</tt>  <tt class="py-line"><tt class="py-docstring">        @param standardIDs: List of standard IDs the user wishes to fuzz on. An ID will randomly be chosen</tt> </tt>
<a name="L267"></a><tt class="py-lineno">267</tt>  <tt class="py-line"><tt class="py-docstring">                            with every new random packet generated. If only 1 ID is input in the list then it will</tt> </tt>
<a name="L268"></a><tt class="py-lineno">268</tt>  <tt class="py-line"><tt class="py-docstring">                            only fuzz on that one ID.</tt> </tt>
<a name="L269"></a><tt class="py-lineno">269</tt>  <tt class="py-line"><tt class="py-docstring">        @type  dbLimits: dictionary</tt> </tt>
<a name="L270"></a><tt class="py-lineno">270</tt>  <tt class="py-line"><tt class="py-docstring">        @param dbLimits: This is a dictionary that holds the limits of each bytes values. </tt> </tt>
<a name="L271"></a><tt class="py-lineno">271</tt>  <tt class="py-line"><tt class="py-docstring">                         Each value in the dictionary will be a list </tt> </tt>
<a name="L272"></a><tt class="py-lineno">272</tt>  <tt class="py-line"><tt class="py-docstring">                         containing the lowest possible value for the byte </tt> </tt>
<a name="L273"></a><tt class="py-lineno">273</tt>  <tt class="py-line"><tt class="py-docstring">                         and the highest possible value. The form is shown below::</tt> </tt>
<a name="L274"></a><tt class="py-lineno">274</tt>  <tt class="py-line"><tt class="py-docstring">                            </tt> </tt>
<a name="L275"></a><tt class="py-lineno">275</tt>  <tt class="py-line"><tt class="py-docstring">                            dbLimits['db0'] = [low, high]</tt> </tt>
<a name="L276"></a><tt class="py-lineno">276</tt>  <tt class="py-line"><tt class="py-docstring">                            dbLimits['db1'] = [low, high]</tt> </tt>
<a name="L277"></a><tt class="py-lineno">277</tt>  <tt class="py-line"><tt class="py-docstring">                            ...</tt> </tt>
<a name="L278"></a><tt class="py-lineno">278</tt>  <tt class="py-line"><tt class="py-docstring">                            dbLimits['db7'] = [low, high] </tt> </tt>
<a name="L279"></a><tt class="py-lineno">279</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L280"></a><tt class="py-lineno">280</tt>  <tt class="py-line"><tt class="py-docstring">        @type period: number</tt> </tt>
<a name="L281"></a><tt class="py-lineno">281</tt>  <tt class="py-line"><tt class="py-docstring">        @param period: The time gap between packet inejctions given in milliseconds</tt> </tt>
<a name="L282"></a><tt class="py-lineno">282</tt>  <tt class="py-line"><tt class="py-docstring">        @type writesPerFuzz: integer</tt> </tt>
<a name="L283"></a><tt class="py-lineno">283</tt>  <tt class="py-line"><tt class="py-docstring">        @param writesPerFuzz: This will be the number of times that each </tt> </tt>
<a name="L284"></a><tt class="py-lineno">284</tt>  <tt class="py-line"><tt class="py-docstring">                              randomly generated packet will be injected onto the bus</tt> </tt>
<a name="L285"></a><tt class="py-lineno">285</tt>  <tt class="py-line"><tt class="py-docstring">                              before a new packet is generated</tt> </tt>
<a name="L286"></a><tt class="py-lineno">286</tt>  <tt class="py-line"><tt class="py-docstring">        @type Fuzzes: integer</tt> </tt>
<a name="L287"></a><tt class="py-lineno">287</tt>  <tt class="py-line"><tt class="py-docstring">        @param Fuzzes: The number of packets to be generated and injected onto bus</tt> </tt>
<a name="L288"></a><tt class="py-lineno">288</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L289"></a><tt class="py-lineno">289</tt>  <tt class="py-line"><tt class="py-docstring">        @rtype: None</tt> </tt>
<a name="L290"></a><tt class="py-lineno">290</tt>  <tt class="py-line"><tt class="py-docstring">        @return: This method does not return anything</tt> </tt>
<a name="L291"></a><tt class="py-lineno">291</tt>  <tt class="py-line"><tt class="py-docstring">                         </tt> </tt>
<a name="L292"></a><tt class="py-lineno">292</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<a name="L293"></a><tt class="py-lineno">293</tt>  <tt class="py-line">        <tt class="py-comment">#print "Fuzzing on standard ID: %d" %standardId</tt> </tt>
<a name="L294"></a><tt class="py-lineno">294</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt class="py-name">serInit</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L295"></a><tt class="py-lineno">295</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-22" class="py-name"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.spitSetup" class="py-name" href="#" onclick="return doclink('link-22', 'spitSetup', 'link-12');">spitSetup</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">)</tt> </tt>
<a name="L296"></a><tt class="py-lineno">296</tt>  <tt class="py-line">        <tt class="py-name">packet</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0x00</tt><tt class="py-op">,</tt><tt class="py-number">0x00</tt><tt class="py-op">,</tt><tt class="py-number">0x08</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> <tt class="py-comment">#empty packet template</tt> </tt>
<a name="L297"></a><tt class="py-lineno">297</tt>  <tt class="py-line">     </tt>
<a name="L298"></a><tt class="py-lineno">298</tt>  <tt class="py-line"> </tt>
<a name="L299"></a><tt class="py-lineno">299</tt>  <tt class="py-line">        <tt class="py-comment">#get folder information (based on today's date)</tt> </tt>
<a name="L300"></a><tt class="py-lineno">300</tt>  <tt class="py-line">        <tt class="py-name">now</tt> <tt class="py-op">=</tt> <tt class="py-name">datetime</tt><tt class="py-op">.</tt><tt class="py-name">datetime</tt><tt class="py-op">.</tt><tt class="py-name">now</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L301"></a><tt class="py-lineno">301</tt>  <tt class="py-line">        <tt class="py-name">datestr</tt> <tt class="py-op">=</tt> <tt class="py-name">now</tt><tt class="py-op">.</tt><tt class="py-name">strftime</tt><tt class="py-op">(</tt><tt class="py-string">"%Y%m%d"</tt><tt class="py-op">)</tt> </tt>
<a name="L302"></a><tt class="py-lineno">302</tt>  <tt class="py-line">        <tt class="py-name">path</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">DATA_LOCATION</tt><tt class="py-op">+</tt><tt class="py-string">"InjectedData/"</tt><tt class="py-op">+</tt><tt class="py-name">datestr</tt><tt class="py-op">+</tt><tt class="py-string">"_GenerationFuzzedPackets.csv"</tt> </tt>
<a name="L303"></a><tt class="py-lineno">303</tt>  <tt class="py-line">        <tt class="py-name">filename</tt> <tt class="py-op">=</tt> <tt class="py-name">path</tt> </tt>
<a name="L304"></a><tt class="py-lineno">304</tt>  <tt class="py-line">        <tt class="py-name">outfile</tt> <tt class="py-op">=</tt> <tt class="py-name">open</tt><tt class="py-op">(</tt><tt class="py-name">filename</tt><tt class="py-op">,</tt><tt class="py-string">'a'</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L305"></a><tt class="py-lineno">305</tt>  <tt class="py-line">        <tt class="py-name">dataWriter</tt> <tt class="py-op">=</tt> <tt class="py-name">csv</tt><tt class="py-op">.</tt><tt class="py-name">writer</tt><tt class="py-op">(</tt><tt class="py-name">outfile</tt><tt class="py-op">,</tt><tt class="py-name">delimiter</tt><tt class="py-op">=</tt><tt class="py-string">','</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L306"></a><tt class="py-lineno">306</tt>  <tt class="py-line">        <tt class="py-comment">#dataWriter.writerow(['# Time     Error        Bytes 1-13']);</tt> </tt>
<a name="L307"></a><tt class="py-lineno">307</tt>  <tt class="py-line">        <tt class="py-comment">#dataWriter.writerow(['#' + description])</tt> </tt>
<a name="L308"></a><tt class="py-lineno">308</tt>  <tt class="py-line">             </tt>
<a name="L309"></a><tt class="py-lineno">309</tt>  <tt class="py-line">        <tt class="py-name">numIds</tt> <tt class="py-op">=</tt> <tt class="py-name">len</tt><tt class="py-op">(</tt><tt class="py-name">standardIDs</tt><tt class="py-op">)</tt> </tt>
<a name="L310"></a><tt class="py-lineno">310</tt>  <tt class="py-line">        <tt class="py-name">fuzzNumber</tt> <tt class="py-op">=</tt> <tt class="py-number">0</tt><tt class="py-op">;</tt> <tt class="py-comment">#: counts the number of packets we have generated</tt> </tt>
<a name="L311"></a><tt class="py-lineno">311</tt>  <tt class="py-line">        <tt class="py-keyword">while</tt><tt class="py-op">(</tt> <tt class="py-name">fuzzNumber</tt> <tt class="py-op">&lt;</tt> <tt class="py-name">Fuzzes</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L312"></a><tt class="py-lineno">312</tt>  <tt class="py-line">            <tt class="py-name">id_new</tt> <tt class="py-op">=</tt> <tt class="py-name">standardIDs</tt><tt class="py-op">[</tt><tt class="py-name">random</tt><tt class="py-op">.</tt><tt class="py-name">randint</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-name">numIds</tt><tt class="py-op">-</tt><tt class="py-number">1</tt><tt class="py-op">)</tt><tt class="py-op">]</tt> </tt>
<a name="L313"></a><tt class="py-lineno">313</tt>  <tt class="py-line">            <tt class="py-keyword">print</tt> <tt class="py-name">id_new</tt> </tt>
<a name="L314"></a><tt class="py-lineno">314</tt>  <tt class="py-line">            <tt class="py-comment">#### split SID into different regs</tt> </tt>
<a name="L315"></a><tt class="py-lineno">315</tt>  <tt class="py-line">            <tt class="py-name">SIDhigh</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">id_new</tt> <tt class="py-op">&gt;&gt;</tt> <tt class="py-number">3</tt><tt class="py-op">)</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0xFF</tt><tt class="py-op">;</tt> <tt class="py-comment"># get SID bits 10:3, rotate them to bits 7:0</tt> </tt>
<a name="L316"></a><tt class="py-lineno">316</tt>  <tt class="py-line">            <tt class="py-name">SIDlow</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">id_new</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0x07</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;&lt;</tt> <tt class="py-number">5</tt><tt class="py-op">;</tt>  <tt class="py-comment"># get SID bits 2:0, rotate them to bits 7:5</tt> </tt>
<a name="L317"></a><tt class="py-lineno">317</tt>  <tt class="py-line">            <tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">SIDhigh</tt> </tt>
<a name="L318"></a><tt class="py-lineno">318</tt>  <tt class="py-line">            <tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">SIDlow</tt> </tt>
<a name="L319"></a><tt class="py-lineno">319</tt>  <tt class="py-line">             </tt>
<a name="L320"></a><tt class="py-lineno">320</tt>  <tt class="py-line">            <tt class="py-comment">#generate a fuzzed packet</tt> </tt>
<a name="L321"></a><tt class="py-lineno">321</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">8</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> <tt class="py-comment"># for each data byte, fuzz it</tt> </tt>
<a name="L322"></a><tt class="py-lineno">322</tt>  <tt class="py-line">                <tt class="py-name">idx</tt> <tt class="py-op">=</tt> <tt class="py-string">"db%d"</tt><tt class="py-op">%</tt><tt class="py-name">i</tt> </tt>
<a name="L323"></a><tt class="py-lineno">323</tt>  <tt class="py-line">                <tt class="py-name">limits</tt> <tt class="py-op">=</tt> <tt class="py-name">dbLimits</tt><tt class="py-op">[</tt><tt class="py-name">idx</tt><tt class="py-op">]</tt> </tt>
<a name="L324"></a><tt class="py-lineno">324</tt>  <tt class="py-line">                <tt class="py-name">value</tt> <tt class="py-op">=</tt> <tt class="py-name">random</tt><tt class="py-op">.</tt><tt class="py-name">randint</tt><tt class="py-op">(</tt><tt class="py-name">limits</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">limits</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-comment">#generate pseudo-random integer value</tt> </tt>
<a name="L325"></a><tt class="py-lineno">325</tt>  <tt class="py-line">                <tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">5</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">value</tt> </tt>
<a name="L326"></a><tt class="py-lineno">326</tt>  <tt class="py-line">            <tt class="py-keyword">print</tt> <tt class="py-name">packet</tt> </tt>
<a name="L327"></a><tt class="py-lineno">327</tt>  <tt class="py-line">            <tt class="py-comment">#put a rough time stamp on the data and get all the data bytes    </tt> </tt>
<a name="L328"></a><tt class="py-lineno">328</tt>  <tt class="py-line">            <tt class="py-name">row</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-name">id_new</tt><tt class="py-op">,</tt><tt class="py-number">8</tt><tt class="py-op">]</tt> <tt class="py-comment"># could make this 8 a variable </tt> </tt>
<a name="L329"></a><tt class="py-lineno">329</tt>  <tt class="py-line">            <tt class="py-name">msg</tt> <tt class="py-op">=</tt> <tt class="py-string">"Injecting: "</tt> </tt>
<a name="L330"></a><tt class="py-lineno">330</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">5</tt><tt class="py-op">,</tt><tt class="py-number">13</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L331"></a><tt class="py-lineno">331</tt>  <tt class="py-line">                <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L332"></a><tt class="py-lineno">332</tt>  <tt class="py-line">                <tt class="py-name">msg</tt> <tt class="py-op">+=</tt> <tt class="py-string">" %d"</tt><tt class="py-op">%</tt><tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">]</tt> </tt>
<a name="L333"></a><tt class="py-lineno">333</tt>  <tt class="py-line">            <tt class="py-comment">#print msg</tt> </tt>
<a name="L334"></a><tt class="py-lineno">334</tt>  <tt class="py-line">            <tt class="py-name">dataWriter</tt><tt class="py-op">.</tt><tt class="py-name">writerow</tt><tt class="py-op">(</tt><tt class="py-name">row</tt><tt class="py-op">)</tt> </tt>
<a name="L335"></a><tt class="py-lineno">335</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-23" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.txpacket" class="py-name" href="#" onclick="return doclink('link-23', 'txpacket', 'link-16');">txpacket</a></tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">)</tt> </tt>
<a name="L336"></a><tt class="py-lineno">336</tt>  <tt class="py-line">            <tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">sleep</tt><tt class="py-op">(</tt><tt class="py-name">period</tt><tt class="py-op">/</tt><tt class="py-number">1000</tt><tt class="py-op">)</tt> </tt>
<a name="L337"></a><tt class="py-lineno">337</tt>  <tt class="py-line">             </tt>
<a name="L338"></a><tt class="py-lineno">338</tt>  <tt class="py-line">            <tt class="py-comment">#inject the packet the given number of times. </tt> </tt>
<a name="L339"></a><tt class="py-lineno">339</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">1</tt><tt class="py-op">,</tt><tt class="py-name">writesPerFuzz</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L340"></a><tt class="py-lineno">340</tt>  <tt class="py-line">                <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-24" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPrts" class="py-name" href="#" onclick="return doclink('link-24', 'MCPrts', 'link-19');">MCPrts</a></tt><tt class="py-op">(</tt><tt class="py-name">TXB0</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">)</tt> </tt>
<a name="L341"></a><tt class="py-lineno">341</tt>  <tt class="py-line">                <tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">sleep</tt><tt class="py-op">(</tt><tt class="py-name">period</tt><tt class="py-op">/</tt><tt class="py-number">1000</tt><tt class="py-op">)</tt> </tt>
<a name="L342"></a><tt class="py-lineno">342</tt>  <tt class="py-line">            <tt class="py-name">fuzzNumber</tt> <tt class="py-op">+=</tt> <tt class="py-number">1</tt> </tt>
<a name="L343"></a><tt class="py-lineno">343</tt>  <tt class="py-line">        <tt class="py-keyword">print</tt> <tt class="py-string">"Fuzzing Complete"</tt>    </tt>
<a name="L344"></a><tt class="py-lineno">344</tt>  <tt class="py-line">        <tt class="py-name">SIDhigh</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-number">1056</tt> <tt class="py-op">&gt;&gt;</tt> <tt class="py-number">3</tt><tt class="py-op">)</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0xFF</tt><tt class="py-op">;</tt> <tt class="py-comment"># get SID bits 10:3, rotate them to bits 7:0</tt> </tt>
<a name="L345"></a><tt class="py-lineno">345</tt>  <tt class="py-line">        <tt class="py-name">SIDlow</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-number">1056</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0x07</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;&lt;</tt> <tt class="py-number">5</tt><tt class="py-op">;</tt>  <tt class="py-comment"># get SID bits 2:0, rotate them to bits 7:5</tt> </tt>
<a name="L346"></a><tt class="py-lineno">346</tt>  <tt class="py-line">        <tt class="py-name">packet</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">SIDhigh</tt><tt class="py-op">,</tt> <tt class="py-name">SIDlow</tt><tt class="py-op">,</tt> <tt class="py-number">0</tt><tt class="py-op">,</tt> <tt class="py-number">0</tt><tt class="py-op">,</tt> <tt class="py-number">8</tt><tt class="py-op">,</tt> <tt class="py-number">65</tt><tt class="py-op">,</tt> <tt class="py-number">255</tt><tt class="py-op">,</tt> <tt class="py-number">32</tt><tt class="py-op">,</tt> <tt class="py-number">120</tt><tt class="py-op">,</tt> <tt class="py-number">0</tt><tt class="py-op">,</tt> <tt class="py-number">0</tt><tt class="py-op">,</tt> <tt class="py-number">1</tt><tt class="py-op">,</tt> <tt class="py-number">247</tt><tt class="py-op">]</tt> </tt>
<a name="L347"></a><tt class="py-lineno">347</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-25" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.txpacket" class="py-name" href="#" onclick="return doclink('link-25', 'txpacket', 'link-16');">txpacket</a></tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">)</tt> </tt>
<a name="L348"></a><tt class="py-lineno">348</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">100</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L349"></a><tt class="py-lineno">349</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-26" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPrts" class="py-name" href="#" onclick="return doclink('link-26', 'MCPrts', 'link-19');">MCPrts</a></tt><tt class="py-op">(</tt><tt class="py-name">TXB0</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">)</tt> </tt>
<a name="L350"></a><tt class="py-lineno">350</tt>  <tt class="py-line">            <tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">sleep</tt><tt class="py-op">(</tt><tt class="py-number">.01</tt><tt class="py-op">)</tt> </tt>
<a name="L351"></a><tt class="py-lineno">351</tt>  <tt class="py-line">        <tt class="py-name">outfile</tt><tt class="py-op">.</tt><tt class="py-name">close</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
</div><a name="L352"></a><tt class="py-lineno">352</tt>  <tt class="py-line">             </tt>
<a name="experiments.generalFuzz"></a><div id="experiments.generalFuzz-def"><a name="L353"></a><tt class="py-lineno">353</tt> <a class="py-toggle" href="#" id="experiments.generalFuzz-toggle" onclick="return toggle('experiments.generalFuzz');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="experiments.experiments-class.html#generalFuzz">generalFuzz</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt><tt class="py-param">freq</tt><tt class="py-op">,</tt> <tt class="py-param">Fuzzes</tt><tt class="py-op">,</tt> <tt class="py-param">period</tt><tt class="py-op">,</tt> <tt class="py-param">writesPerFuzz</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments.generalFuzz-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="experiments.generalFuzz-expanded"><a name="L354"></a><tt class="py-lineno">354</tt>  <tt class="py-line">        <tt class="py-docstring">"""</tt> </tt>
<a name="L355"></a><tt class="py-lineno">355</tt>  <tt class="py-line"><tt class="py-docstring">        The method will inject properly formatted, randomly generated </tt> </tt>
<a name="L356"></a><tt class="py-lineno">356</tt>  <tt class="py-line"><tt class="py-docstring">        messages at a given period for a I{writesPerFuzz} </tt> </tt>
<a name="L357"></a><tt class="py-lineno">357</tt>  <tt class="py-line"><tt class="py-docstring">        number of times. A new random standard id will be chosen with </tt> </tt>
<a name="L358"></a><tt class="py-lineno">358</tt>  <tt class="py-line"><tt class="py-docstring">        each newly generated packet. IDs will be chosen from the full</tt> </tt>
<a name="L359"></a><tt class="py-lineno">359</tt>  <tt class="py-line"><tt class="py-docstring">        range of potential ids ranging from 0 to 4095. The packets </tt> </tt>
<a name="L360"></a><tt class="py-lineno">360</tt>  <tt class="py-line"><tt class="py-docstring">        that are injected into the bus will all be saved in the following path</tt> </tt>
<a name="L361"></a><tt class="py-lineno">361</tt>  <tt class="py-line"><tt class="py-docstring">        DATALOCATION/InjectedData/(today's date (YYYYMMDD))_GenerationFuzzedPackets.csv. </tt> </tt>
<a name="L362"></a><tt class="py-lineno">362</tt>  <tt class="py-line"><tt class="py-docstring">        An example filename would be 20130222_GenerationFuzzedPackets.csv</tt> </tt>
<a name="L363"></a><tt class="py-lineno">363</tt>  <tt class="py-line"><tt class="py-docstring">        Where DATALOCATION is provided when the class is initiated. The data will be saved as integers.</tt> </tt>
<a name="L364"></a><tt class="py-lineno">364</tt>  <tt class="py-line"><tt class="py-docstring">        Each row will be formatted in the following form::</tt> </tt>
<a name="L365"></a><tt class="py-lineno">365</tt>  <tt class="py-line"><tt class="py-docstring">                     row = [time of injection, standardID, 8, db0, db1, db2, db3, db4, db5, db6, db7]</tt> </tt>
<a name="L366"></a><tt class="py-lineno">366</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L367"></a><tt class="py-lineno">367</tt>  <tt class="py-line"><tt class="py-docstring">        @type  freq: number</tt> </tt>
<a name="L368"></a><tt class="py-lineno">368</tt>  <tt class="py-line"><tt class="py-docstring">        @param freq: The frequency at which the bus is communicating</tt> </tt>
<a name="L369"></a><tt class="py-lineno">369</tt>  <tt class="py-line"><tt class="py-docstring">        @type period: number</tt> </tt>
<a name="L370"></a><tt class="py-lineno">370</tt>  <tt class="py-line"><tt class="py-docstring">        @param period: The time gap between packet inejctions given in milliseconds</tt> </tt>
<a name="L371"></a><tt class="py-lineno">371</tt>  <tt class="py-line"><tt class="py-docstring">        @type writesPerFuzz: integer</tt> </tt>
<a name="L372"></a><tt class="py-lineno">372</tt>  <tt class="py-line"><tt class="py-docstring">        @param writesPerFuzz: This will be the number of times that each randomly </tt> </tt>
<a name="L373"></a><tt class="py-lineno">373</tt>  <tt class="py-line"><tt class="py-docstring">                              generated packet will be injected onto the bus</tt> </tt>
<a name="L374"></a><tt class="py-lineno">374</tt>  <tt class="py-line"><tt class="py-docstring">                              before a new packet is generated</tt> </tt>
<a name="L375"></a><tt class="py-lineno">375</tt>  <tt class="py-line"><tt class="py-docstring">        @type Fuzzes: integer</tt> </tt>
<a name="L376"></a><tt class="py-lineno">376</tt>  <tt class="py-line"><tt class="py-docstring">        @param Fuzzes: The number of packets to be generated and injected onto bus</tt> </tt>
<a name="L377"></a><tt class="py-lineno">377</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L378"></a><tt class="py-lineno">378</tt>  <tt class="py-line"><tt class="py-docstring">        @rtype: None</tt> </tt>
<a name="L379"></a><tt class="py-lineno">379</tt>  <tt class="py-line"><tt class="py-docstring">        @return: This method does not return anything</tt> </tt>
<a name="L380"></a><tt class="py-lineno">380</tt>  <tt class="py-line"><tt class="py-docstring">                         </tt> </tt>
<a name="L381"></a><tt class="py-lineno">381</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<a name="L382"></a><tt class="py-lineno">382</tt>  <tt class="py-line">        <tt class="py-comment">#print "Fuzzing on standard ID: %d" %standardId</tt> </tt>
<a name="L383"></a><tt class="py-lineno">383</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt class="py-name">serInit</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L384"></a><tt class="py-lineno">384</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-27" class="py-name"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.spitSetup" class="py-name" href="#" onclick="return doclink('link-27', 'spitSetup', 'link-12');">spitSetup</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">)</tt> </tt>
<a name="L385"></a><tt class="py-lineno">385</tt>  <tt class="py-line">        <tt class="py-name">packet</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0x00</tt><tt class="py-op">,</tt><tt class="py-number">0x00</tt><tt class="py-op">,</tt><tt class="py-number">0x08</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> <tt class="py-comment">#empty template</tt> </tt>
<a name="L386"></a><tt class="py-lineno">386</tt>  <tt class="py-line">         </tt>
<a name="L387"></a><tt class="py-lineno">387</tt>  <tt class="py-line">        <tt class="py-comment">#get folder information (based on today's date)</tt> </tt>
<a name="L388"></a><tt class="py-lineno">388</tt>  <tt class="py-line">        <tt class="py-name">now</tt> <tt class="py-op">=</tt> <tt class="py-name">datetime</tt><tt class="py-op">.</tt><tt class="py-name">datetime</tt><tt class="py-op">.</tt><tt class="py-name">now</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L389"></a><tt class="py-lineno">389</tt>  <tt class="py-line">        <tt class="py-name">datestr</tt> <tt class="py-op">=</tt> <tt class="py-name">now</tt><tt class="py-op">.</tt><tt class="py-name">strftime</tt><tt class="py-op">(</tt><tt class="py-string">"%Y%m%d"</tt><tt class="py-op">)</tt> </tt>
<a name="L390"></a><tt class="py-lineno">390</tt>  <tt class="py-line">        <tt class="py-name">path</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">DATA_LOCATION</tt><tt class="py-op">+</tt><tt class="py-string">"InjectedData/"</tt><tt class="py-op">+</tt><tt class="py-name">datestr</tt><tt class="py-op">+</tt><tt class="py-string">"_GenerationFuzzedPackets.csv"</tt> </tt>
<a name="L391"></a><tt class="py-lineno">391</tt>  <tt class="py-line">        <tt class="py-name">filename</tt> <tt class="py-op">=</tt> <tt class="py-name">path</tt> </tt>
<a name="L392"></a><tt class="py-lineno">392</tt>  <tt class="py-line">        <tt class="py-name">outfile</tt> <tt class="py-op">=</tt> <tt class="py-name">open</tt><tt class="py-op">(</tt><tt class="py-name">filename</tt><tt class="py-op">,</tt><tt class="py-string">'a'</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L393"></a><tt class="py-lineno">393</tt>  <tt class="py-line">        <tt class="py-name">dataWriter</tt> <tt class="py-op">=</tt> <tt class="py-name">csv</tt><tt class="py-op">.</tt><tt class="py-name">writer</tt><tt class="py-op">(</tt><tt class="py-name">outfile</tt><tt class="py-op">,</tt><tt class="py-name">delimiter</tt><tt class="py-op">=</tt><tt class="py-string">','</tt><tt class="py-op">)</tt><tt class="py-op">;</tt> </tt>
<a name="L394"></a><tt class="py-lineno">394</tt>  <tt class="py-line">        <tt class="py-comment">#dataWriter.writerow(['# Time     Error        Bytes 1-13']);</tt> </tt>
<a name="L395"></a><tt class="py-lineno">395</tt>  <tt class="py-line">        <tt class="py-comment">#dataWriter.writerow(['#' + description])</tt> </tt>
<a name="L396"></a><tt class="py-lineno">396</tt>  <tt class="py-line">             </tt>
<a name="L397"></a><tt class="py-lineno">397</tt>  <tt class="py-line">        <tt class="py-name">fuzzNumber</tt> <tt class="py-op">=</tt> <tt class="py-number">0</tt><tt class="py-op">;</tt> <tt class="py-comment">#: counts the number of packets we have generated</tt> </tt>
<a name="L398"></a><tt class="py-lineno">398</tt>  <tt class="py-line">        <tt class="py-keyword">while</tt><tt class="py-op">(</tt> <tt class="py-name">fuzzNumber</tt> <tt class="py-op">&lt;</tt> <tt class="py-name">Fuzzes</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L399"></a><tt class="py-lineno">399</tt>  <tt class="py-line">            <tt class="py-comment">#generate new random standard id in the full range of possible values</tt> </tt>
<a name="L400"></a><tt class="py-lineno">400</tt>  <tt class="py-line">            <tt class="py-name">id_new</tt> <tt class="py-op">=</tt> <tt class="py-name">random</tt><tt class="py-op">.</tt><tt class="py-name">randint</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">4095</tt><tt class="py-op">)</tt>  </tt>
<a name="L401"></a><tt class="py-lineno">401</tt>  <tt class="py-line">            <tt class="py-comment">#print id_new</tt> </tt>
<a name="L402"></a><tt class="py-lineno">402</tt>  <tt class="py-line">            <tt class="py-comment">#### split SID into different regs</tt> </tt>
<a name="L403"></a><tt class="py-lineno">403</tt>  <tt class="py-line">            <tt class="py-name">SIDhigh</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">id_new</tt> <tt class="py-op">&gt;&gt;</tt> <tt class="py-number">3</tt><tt class="py-op">)</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0xFF</tt><tt class="py-op">;</tt> <tt class="py-comment"># get SID bits 10:3, rotate them to bits 7:0</tt> </tt>
<a name="L404"></a><tt class="py-lineno">404</tt>  <tt class="py-line">            <tt class="py-name">SIDlow</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">id_new</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0x07</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;&lt;</tt> <tt class="py-number">5</tt><tt class="py-op">;</tt>  <tt class="py-comment"># get SID bits 2:0, rotate them to bits 7:5</tt> </tt>
<a name="L405"></a><tt class="py-lineno">405</tt>  <tt class="py-line">            <tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">SIDhigh</tt> </tt>
<a name="L406"></a><tt class="py-lineno">406</tt>  <tt class="py-line">            <tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">SIDlow</tt> </tt>
<a name="L407"></a><tt class="py-lineno">407</tt>  <tt class="py-line">             </tt>
<a name="L408"></a><tt class="py-lineno">408</tt>  <tt class="py-line">            <tt class="py-comment">#generate a fuzzed packet</tt> </tt>
<a name="L409"></a><tt class="py-lineno">409</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">8</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> <tt class="py-comment"># for each data byte, fuzz it</tt> </tt>
<a name="L410"></a><tt class="py-lineno">410</tt>  <tt class="py-line">                <tt class="py-name">idx</tt> <tt class="py-op">=</tt> <tt class="py-string">"db%d"</tt><tt class="py-op">%</tt><tt class="py-name">i</tt> </tt>
<a name="L411"></a><tt class="py-lineno">411</tt>  <tt class="py-line">                 </tt>
<a name="L412"></a><tt class="py-lineno">412</tt>  <tt class="py-line">                <tt class="py-name">value</tt> <tt class="py-op">=</tt> <tt class="py-name">random</tt><tt class="py-op">.</tt><tt class="py-name">randint</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt> <tt class="py-number">255</tt><tt class="py-op">)</tt> <tt class="py-comment">#generate pseudo-random integer value</tt> </tt>
<a name="L413"></a><tt class="py-lineno">413</tt>  <tt class="py-line">                <tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">+</tt><tt class="py-number">5</tt><tt class="py-op">]</tt> <tt class="py-op">=</tt> <tt class="py-name">value</tt> </tt>
<a name="L414"></a><tt class="py-lineno">414</tt>  <tt class="py-line">            <tt class="py-comment">#print packet</tt> </tt>
<a name="L415"></a><tt class="py-lineno">415</tt>  <tt class="py-line">            <tt class="py-comment">#put a rough time stamp on the data and get all the data bytes    </tt> </tt>
<a name="L416"></a><tt class="py-lineno">416</tt>  <tt class="py-line">            <tt class="py-name">row</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-name">id_new</tt><tt class="py-op">,</tt><tt class="py-number">8</tt><tt class="py-op">]</tt>  </tt>
<a name="L417"></a><tt class="py-lineno">417</tt>  <tt class="py-line">            <tt class="py-string">"""@todo: allow for varied packet lengths"""</tt> </tt>
<a name="L418"></a><tt class="py-lineno">418</tt>  <tt class="py-line">            <tt class="py-name">msg</tt> <tt class="py-op">=</tt> <tt class="py-string">"Injecting: "</tt> </tt>
<a name="L419"></a><tt class="py-lineno">419</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">5</tt><tt class="py-op">,</tt><tt class="py-number">13</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L420"></a><tt class="py-lineno">420</tt>  <tt class="py-line">                <tt class="py-name">row</tt><tt class="py-op">.</tt><tt class="py-name">append</tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L421"></a><tt class="py-lineno">421</tt>  <tt class="py-line">                <tt class="py-name">msg</tt> <tt class="py-op">+=</tt> <tt class="py-string">" %d"</tt><tt class="py-op">%</tt><tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">]</tt> </tt>
<a name="L422"></a><tt class="py-lineno">422</tt>  <tt class="py-line">            <tt class="py-comment">#print msg</tt> </tt>
<a name="L423"></a><tt class="py-lineno">423</tt>  <tt class="py-line">            <tt class="py-name">dataWriter</tt><tt class="py-op">.</tt><tt class="py-name">writerow</tt><tt class="py-op">(</tt><tt class="py-name">row</tt><tt class="py-op">)</tt> </tt>
<a name="L424"></a><tt class="py-lineno">424</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-28" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.txpacket" class="py-name" href="#" onclick="return doclink('link-28', 'txpacket', 'link-16');">txpacket</a></tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">)</tt> </tt>
<a name="L425"></a><tt class="py-lineno">425</tt>  <tt class="py-line">            <tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">sleep</tt><tt class="py-op">(</tt><tt class="py-name">period</tt><tt class="py-op">/</tt><tt class="py-number">1000</tt><tt class="py-op">)</tt> </tt>
<a name="L426"></a><tt class="py-lineno">426</tt>  <tt class="py-line">             </tt>
<a name="L427"></a><tt class="py-lineno">427</tt>  <tt class="py-line">            <tt class="py-comment">#inject the packet the given number of times. </tt> </tt>
<a name="L428"></a><tt class="py-lineno">428</tt>  <tt class="py-line">            <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">1</tt><tt class="py-op">,</tt><tt class="py-name">writesPerFuzz</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L429"></a><tt class="py-lineno">429</tt>  <tt class="py-line">                <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-29" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPrts" class="py-name" href="#" onclick="return doclink('link-29', 'MCPrts', 'link-19');">MCPrts</a></tt><tt class="py-op">(</tt><tt class="py-name">TXB0</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">)</tt> </tt>
<a name="L430"></a><tt class="py-lineno">430</tt>  <tt class="py-line">                <tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">sleep</tt><tt class="py-op">(</tt><tt class="py-name">period</tt><tt class="py-op">/</tt><tt class="py-number">1000</tt><tt class="py-op">)</tt> </tt>
<a name="L431"></a><tt class="py-lineno">431</tt>  <tt class="py-line">            <tt class="py-name">fuzzNumber</tt> <tt class="py-op">+=</tt> <tt class="py-number">1</tt> </tt>
<a name="L432"></a><tt class="py-lineno">432</tt>  <tt class="py-line">        <tt class="py-keyword">print</tt> <tt class="py-string">"Fuzzing Complete"</tt>    </tt>
<a name="L433"></a><tt class="py-lineno">433</tt>  <tt class="py-line">        <tt class="py-name">outfile</tt><tt class="py-op">.</tt><tt class="py-name">close</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
</div><a name="L434"></a><tt class="py-lineno">434</tt>  <tt class="py-line">     </tt>
<a name="L435"></a><tt class="py-lineno">435</tt>  <tt class="py-line">    <tt class="py-comment"># assumes 8 byte packets</tt> </tt>
<a name="experiments.packetRespond"></a><div id="experiments.packetRespond-def"><a name="L436"></a><tt class="py-lineno">436</tt> <a class="py-toggle" href="#" id="experiments.packetRespond-toggle" onclick="return toggle('experiments.packetRespond');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="experiments.experiments-class.html#packetRespond">packetRespond</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt><tt class="py-param">freq</tt><tt class="py-op">,</tt> <tt class="py-param">time</tt><tt class="py-op">,</tt> <tt class="py-param">repeats</tt><tt class="py-op">,</tt> <tt class="py-param">period</tt><tt class="py-op">,</tt>  <tt class="py-param">responseID</tt><tt class="py-op">,</tt> <tt class="py-param">respondPacket</tt><tt class="py-op">,</tt><tt class="py-param">listenID</tt><tt class="py-op">,</tt> <tt class="py-param">listenPacket</tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="experiments.packetRespond-collapsed" style="display:none;" pad="+++" indent="++++++++"></div><div id="experiments.packetRespond-expanded"><a name="L437"></a><tt class="py-lineno">437</tt>  <tt class="py-line">        <tt class="py-docstring">"""</tt> </tt>
<a name="L438"></a><tt class="py-lineno">438</tt>  <tt class="py-line"><tt class="py-docstring">        This method will allow the user to listen for a specific packet and then respond with a given message.</tt> </tt>
<a name="L439"></a><tt class="py-lineno">439</tt>  <tt class="py-line"><tt class="py-docstring">        If no listening packet is included then the method will only listen for the id and respond with the specified</tt> </tt>
<a name="L440"></a><tt class="py-lineno">440</tt>  <tt class="py-line"><tt class="py-docstring">        packet when it receives a message from that id. This process will continue for the given amount of time (in seconds). </tt> </tt>
<a name="L441"></a><tt class="py-lineno">441</tt>  <tt class="py-line"><tt class="py-docstring">        and with each message received that matches the listenPacket and ID the transmit message will be sent the I{repeats} number</tt> </tt>
<a name="L442"></a><tt class="py-lineno">442</tt>  <tt class="py-line"><tt class="py-docstring">        of times at the specified I{period}. This message assumes a packet length of 8 for both messages, although the listenPacket can be None</tt> </tt>
<a name="L443"></a><tt class="py-lineno">443</tt>  <tt class="py-line"><tt class="py-docstring">        </tt> </tt>
<a name="L444"></a><tt class="py-lineno">444</tt>  <tt class="py-line"><tt class="py-docstring">        @type freq: number</tt> </tt>
<a name="L445"></a><tt class="py-lineno">445</tt>  <tt class="py-line"><tt class="py-docstring">        @param freq: Frequency of the CAN bus</tt> </tt>
<a name="L446"></a><tt class="py-lineno">446</tt>  <tt class="py-line"><tt class="py-docstring">        @type time: number</tt> </tt>
<a name="L447"></a><tt class="py-lineno">447</tt>  <tt class="py-line"><tt class="py-docstring">        @param time: Length of time to perform the packet listen/response in seconds.</tt> </tt>
<a name="L448"></a><tt class="py-lineno">448</tt>  <tt class="py-line"><tt class="py-docstring">        @type repeats: Integer</tt> </tt>
<a name="L449"></a><tt class="py-lineno">449</tt>  <tt class="py-line"><tt class="py-docstring">        @param repeats: The number of times the response packet will be injected onto the bus after the listening </tt> </tt>
<a name="L450"></a><tt class="py-lineno">450</tt>  <tt class="py-line"><tt class="py-docstring">                        criteria has been met.</tt> </tt>
<a name="L451"></a><tt class="py-lineno">451</tt>  <tt class="py-line"><tt class="py-docstring">        @type period: number</tt> </tt>
<a name="L452"></a><tt class="py-lineno">452</tt>  <tt class="py-line"><tt class="py-docstring">        @param period: The time interval between messages being injected onto the CAN bus. This will be specified in milliseconds</tt> </tt>
<a name="L453"></a><tt class="py-lineno">453</tt>  <tt class="py-line"><tt class="py-docstring">        @type responseID: Integer</tt> </tt>
<a name="L454"></a><tt class="py-lineno">454</tt>  <tt class="py-line"><tt class="py-docstring">        @param responseID: The standard ID of the message that we want to inject</tt> </tt>
<a name="L455"></a><tt class="py-lineno">455</tt>  <tt class="py-line"><tt class="py-docstring">        @type respondPacket: List of integers</tt> </tt>
<a name="L456"></a><tt class="py-lineno">456</tt>  <tt class="py-line"><tt class="py-docstring">        @param respondPacket: The data we wish to inject into the bus. In the format where respondPacket[0] = databyte 0 ... respondPacket[7] = databyte 7</tt> </tt>
<a name="L457"></a><tt class="py-lineno">457</tt>  <tt class="py-line"><tt class="py-docstring">                              This assumes a packet length of 8.</tt> </tt>
<a name="L458"></a><tt class="py-lineno">458</tt>  <tt class="py-line"><tt class="py-docstring">        @type listenID: Integer</tt> </tt>
<a name="L459"></a><tt class="py-lineno">459</tt>  <tt class="py-line"><tt class="py-docstring">        @param listenID: The standard ID of the messages that we are listening for. When we read the correct message from this ID off of the bus, the method will</tt> </tt>
<a name="L460"></a><tt class="py-lineno">460</tt>  <tt class="py-line"><tt class="py-docstring">                         begin re-injecting the responsePacket on the responseID</tt> </tt>
<a name="L461"></a><tt class="py-lineno">461</tt>  <tt class="py-line"><tt class="py-docstring">        @type listenPacket: List of Integers</tt> </tt>
<a name="L462"></a><tt class="py-lineno">462</tt>  <tt class="py-line"><tt class="py-docstring">        @param listenPacket: The data we wish to listen for before we inject packets. This will be a list of the databytes, stored as integers such that</tt> </tt>
<a name="L463"></a><tt class="py-lineno">463</tt>  <tt class="py-line"><tt class="py-docstring">                             listenPacket[0] = data byte 0, ..., listenPacket[7] = databyte 7. This assumes a packet length of 8. This input can be None and this</tt> </tt>
<a name="L464"></a><tt class="py-lineno">464</tt>  <tt class="py-line"><tt class="py-docstring">                             will lead to the program only listening for the standardID and injecting the response as soon as any message from that ID is given</tt> </tt>
<a name="L465"></a><tt class="py-lineno">465</tt>  <tt class="py-line"><tt class="py-docstring">        """</tt> </tt>
<a name="L466"></a><tt class="py-lineno">466</tt>  <tt class="py-line">         </tt>
<a name="L467"></a><tt class="py-lineno">467</tt>  <tt class="py-line">         </tt>
<a name="L468"></a><tt class="py-lineno">468</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt class="py-name">serInit</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L469"></a><tt class="py-lineno">469</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-30" class="py-name"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.spitSetup" class="py-name" href="#" onclick="return doclink('link-30', 'spitSetup', 'link-12');">spitSetup</a></tt><tt class="py-op">(</tt><tt class="py-name">freq</tt><tt class="py-op">)</tt> </tt>
<a name="L470"></a><tt class="py-lineno">470</tt>  <tt class="py-line">         </tt>
<a name="L471"></a><tt class="py-lineno">471</tt>  <tt class="py-line">        <tt class="py-comment">#formulate response packet</tt> </tt>
<a name="L472"></a><tt class="py-lineno">472</tt>  <tt class="py-line">        <tt class="py-name">SIDhigh</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">responseID</tt> <tt class="py-op">&gt;&gt;</tt> <tt class="py-number">3</tt><tt class="py-op">)</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0xFF</tt><tt class="py-op">;</tt> <tt class="py-comment"># get SID bits 10:3, rotate them to bits 7:0</tt> </tt>
<a name="L473"></a><tt class="py-lineno">473</tt>  <tt class="py-line">        <tt class="py-name">SIDlow</tt> <tt class="py-op">=</tt> <tt class="py-op">(</tt><tt class="py-name">responseID</tt> <tt class="py-op">&amp;</tt> <tt class="py-number">0x07</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;&lt;</tt> <tt class="py-number">5</tt><tt class="py-op">;</tt>  <tt class="py-comment"># get SID bits 2:0, rotate them to bits 7:5</tt> </tt>
<a name="L474"></a><tt class="py-lineno">474</tt>  <tt class="py-line">        <tt class="py-comment">#resPacket[0] = SIDhigh</tt> </tt>
<a name="L475"></a><tt class="py-lineno">475</tt>  <tt class="py-line">        <tt class="py-comment">#resPacket[1] = SIDlow</tt> </tt>
<a name="L476"></a><tt class="py-lineno">476</tt>  <tt class="py-line">        <tt class="py-name">resPacket</tt> <tt class="py-op">=</tt> <tt class="py-op">[</tt><tt class="py-name">SIDhigh</tt><tt class="py-op">,</tt> <tt class="py-name">SIDlow</tt><tt class="py-op">,</tt> <tt class="py-number">0x00</tt><tt class="py-op">,</tt><tt class="py-number">0x00</tt><tt class="py-op">,</tt> <tt class="py-comment"># pad out EID regs</tt> </tt>
<a name="L477"></a><tt class="py-lineno">477</tt>  <tt class="py-line">                  <tt class="py-number">0x08</tt><tt class="py-op">,</tt> <tt class="py-comment"># bit 6 must be set to 0 for data frame (1 for RTR) </tt> </tt>
<a name="L478"></a><tt class="py-lineno">478</tt>  <tt class="py-line">                  <tt class="py-comment"># lower nibble is DLC                   </tt> </tt>
<a name="L479"></a><tt class="py-lineno">479</tt>  <tt class="py-line">                 <tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">2</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">3</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">4</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">5</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">6</tt><tt class="py-op">]</tt><tt class="py-op">,</tt><tt class="py-name">respondPacket</tt><tt class="py-op">[</tt><tt class="py-number">7</tt><tt class="py-op">]</tt><tt class="py-op">]</tt> </tt>
<a name="L480"></a><tt class="py-lineno">480</tt>  <tt class="py-line">        <tt class="py-comment">#load packet/send once</tt> </tt>
<a name="L481"></a><tt class="py-lineno">481</tt>  <tt class="py-line">        <tt class="py-string">"""@todo: make this only load the data onto the chip and not send """</tt> </tt>
<a name="L482"></a><tt class="py-lineno">482</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-31" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.txpacket" class="py-name" href="#" onclick="return doclink('link-31', 'txpacket', 'link-16');">txpacket</a></tt><tt class="py-op">(</tt><tt class="py-name">resPacket</tt><tt class="py-op">)</tt>  </tt>
<a name="L483"></a><tt class="py-lineno">483</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-32" class="py-name"><a title="GoodFETMCPCANCommunication.GoodFETMCPCANCommunication.addFilter" class="py-name" href="#" onclick="return doclink('link-32', 'addFilter', 'link-13');">addFilter</a></tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-name">listenID</tt><tt class="py-op">,</tt><tt class="py-name">listenID</tt><tt class="py-op">,</tt><tt class="py-name">listenID</tt><tt class="py-op">,</tt><tt class="py-name">listenID</tt><tt class="py-op">,</tt> <tt class="py-name">listenID</tt><tt class="py-op">,</tt> <tt class="py-name">listenID</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> <tt class="py-comment">#listen only for this packet</tt> </tt>
<a name="L484"></a><tt class="py-lineno">484</tt>  <tt class="py-line">        <tt class="py-name">startTime</tt> <tt class="py-op">=</tt> <tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L485"></a><tt class="py-lineno">485</tt>  <tt class="py-line">        <tt class="py-name">packet</tt> <tt class="py-op">=</tt> <tt class="py-name">None</tt> </tt>
<a name="L486"></a><tt class="py-lineno">486</tt>  <tt class="py-line">        <tt class="py-keyword">while</tt><tt class="py-op">(</tt> <tt class="py-op">(</tt><tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-op">-</tt> <tt class="py-name">startTime</tt><tt class="py-op">)</tt> <tt class="py-op">&lt;</tt> <tt class="py-name">time</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L487"></a><tt class="py-lineno">487</tt>  <tt class="py-line">            <tt class="py-name">packet</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-33" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.rxpacket" class="py-name" href="#" onclick="return doclink('link-33', 'rxpacket', 'link-14');">rxpacket</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L488"></a><tt class="py-lineno">488</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">packet</tt> <tt class="py-op">!=</tt> <tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L489"></a><tt class="py-lineno">489</tt>  <tt class="py-line">                <tt class="py-keyword">print</tt> <tt class="py-string">"packet read in, responding now"</tt> </tt>
<a name="L490"></a><tt class="py-lineno">490</tt>  <tt class="py-line">                <tt class="py-comment"># assume the ids already match since we are filtering for the id</tt> </tt>
<a name="L491"></a><tt class="py-lineno">491</tt>  <tt class="py-line">                 </tt>
<a name="L492"></a><tt class="py-lineno">492</tt>  <tt class="py-line">                <tt class="py-comment">#compare packet received to desired packet</tt> </tt>
<a name="L493"></a><tt class="py-lineno">493</tt>  <tt class="py-line">                <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">listenPacket</tt> <tt class="py-op">==</tt> <tt class="py-name">None</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> <tt class="py-comment"># no packets given, just want the id</tt> </tt>
<a name="L494"></a><tt class="py-lineno">494</tt>  <tt class="py-line">                    <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-name">repeats</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L495"></a><tt class="py-lineno">495</tt>  <tt class="py-line">                        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-34" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPrts" class="py-name" href="#" onclick="return doclink('link-34', 'MCPrts', 'link-19');">MCPrts</a></tt><tt class="py-op">(</tt><tt class="py-name">TXB0</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">)</tt> </tt>
<a name="L496"></a><tt class="py-lineno">496</tt>  <tt class="py-line">                        <tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">sleep</tt><tt class="py-op">(</tt><tt class="py-name">period</tt><tt class="py-op">/</tt><tt class="py-number">1000</tt><tt class="py-op">)</tt> </tt>
<a name="L497"></a><tt class="py-lineno">497</tt>  <tt class="py-line">                <tt class="py-keyword">else</tt><tt class="py-op">:</tt> <tt class="py-comment">#compare packets</tt> </tt>
<a name="L498"></a><tt class="py-lineno">498</tt>  <tt class="py-line">                    <tt class="py-name">sid</tt> <tt class="py-op">=</tt>  <tt class="py-name">ord</tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-number">0</tt><tt class="py-op">]</tt><tt class="py-op">)</tt><tt class="py-op">&lt;&lt;</tt><tt class="py-number">3</tt> <tt class="py-op">|</tt> <tt class="py-name">ord</tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-number">1</tt><tt class="py-op">]</tt><tt class="py-op">)</tt><tt class="py-op">&gt;&gt;</tt><tt class="py-number">5</tt> </tt>
<a name="L499"></a><tt class="py-lineno">499</tt>  <tt class="py-line">                    <tt class="py-keyword">print</tt> <tt class="py-string">"standard id of packet recieved: "</tt><tt class="py-op">,</tt> <tt class="py-name">sid</tt> <tt class="py-comment">#standard ID</tt> </tt>
<a name="L500"></a><tt class="py-lineno">500</tt>  <tt class="py-line">                    <tt class="py-name">msg</tt> <tt class="py-op">=</tt> <tt class="py-string">""</tt> </tt>
<a name="L501"></a><tt class="py-lineno">501</tt>  <tt class="py-line">                    <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">range</tt><tt class="py-op">(</tt><tt class="py-number">0</tt><tt class="py-op">,</tt><tt class="py-number">8</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L502"></a><tt class="py-lineno">502</tt>  <tt class="py-line">                        <tt class="py-name">idx</tt> <tt class="py-op">=</tt> <tt class="py-number">5</tt> <tt class="py-op">+</tt> <tt class="py-name">i</tt> </tt>
<a name="L503"></a><tt class="py-lineno">503</tt>  <tt class="py-line">                        <tt class="py-name">byteIn</tt> <tt class="py-op">=</tt> <tt class="py-name">ord</tt><tt class="py-op">(</tt><tt class="py-name">packet</tt><tt class="py-op">[</tt><tt class="py-name">idx</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L504"></a><tt class="py-lineno">504</tt>  <tt class="py-line">                        <tt class="py-name">msg</tt> <tt class="py-op">+=</tt> <tt class="py-string">" %d"</tt> <tt class="py-op">%</tt><tt class="py-name">byteIn</tt> </tt>
<a name="L505"></a><tt class="py-lineno">505</tt>  <tt class="py-line">                        <tt class="py-name">compareIn</tt> <tt class="py-op">=</tt> <tt class="py-name">listenPacket</tt><tt class="py-op">[</tt><tt class="py-name">i</tt><tt class="py-op">]</tt> </tt>
<a name="L506"></a><tt class="py-lineno">506</tt>  <tt class="py-line">                        <tt class="py-keyword">print</tt> <tt class="py-name">byteIn</tt><tt class="py-op">,</tt> <tt class="py-name">compareIn</tt> </tt>
<a name="L507"></a><tt class="py-lineno">507</tt>  <tt class="py-line">                        <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">byteIn</tt> <tt class="py-op">!=</tt> <tt class="py-name">compareIn</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L508"></a><tt class="py-lineno">508</tt>  <tt class="py-line">                            <tt class="py-name">packet</tt> <tt class="py-op">==</tt> <tt class="py-name">None</tt> </tt>
<a name="L509"></a><tt class="py-lineno">509</tt>  <tt class="py-line">                            <tt class="py-keyword">print</tt> <tt class="py-string">"packet did not match"</tt> </tt>
<a name="L510"></a><tt class="py-lineno">510</tt>  <tt class="py-line">                            <tt class="py-keyword">break</tt> </tt>
<a name="L511"></a><tt class="py-lineno">511</tt>  <tt class="py-line">                    <tt class="py-keyword">print</tt> <tt class="py-name">msg</tt> </tt>
<a name="L512"></a><tt class="py-lineno">512</tt>  <tt class="py-line">                    <tt class="py-keyword">if</tt><tt class="py-op">(</tt> <tt class="py-name">packet</tt> <tt class="py-op">!=</tt> <tt class="py-name">None</tt> <tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L513"></a><tt class="py-lineno">513</tt>  <tt class="py-line">                        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">client</tt><tt class="py-op">.</tt><tt id="link-35" class="py-name"><a title="GoodFETMCPCAN.GoodFETMCPCAN.MCPrts" class="py-name" href="#" onclick="return doclink('link-35', 'MCPrts', 'link-19');">MCPrts</a></tt><tt class="py-op">(</tt><tt class="py-name">TXB0</tt><tt class="py-op">=</tt><tt class="py-name">True</tt><tt class="py-op">)</tt> </tt>
<a name="L514"></a><tt class="py-lineno">514</tt>  <tt class="py-line">                        <tt class="py-name">tT</tt><tt class="py-op">.</tt><tt class="py-name">sleep</tt><tt class="py-op">(</tt><tt class="py-name">period</tt><tt class="py-op">/</tt><tt class="py-number">1000</tt><tt class="py-op">)</tt> </tt>
<a name="L515"></a><tt class="py-lineno">515</tt>  <tt class="py-line">        <tt class="py-keyword">print</tt> <tt class="py-string">"Response Listening Terminated."</tt> </tt>
</div></div><a name="L516"></a><tt class="py-lineno">516</tt>  <tt class="py-line">                 </tt>
<a name="L517"></a><tt class="py-lineno">517</tt>  <tt class="py-line">         </tt>
<a name="L518"></a><tt class="py-lineno">518</tt>  <tt class="py-line"><tt class="py-comment">#    def generationFuzzRandomID(self, freq, standardIDs, dbLimits, period, writesPerFuzz, Fuzzes):</tt> </tt>
<a name="L519"></a><tt class="py-lineno">519</tt>  <tt class="py-line"><tt class="py-comment">#        print "Fuzzing on standard ID: %d" %standardId</tt> </tt>
<a name="L520"></a><tt class="py-lineno">520</tt>  <tt class="py-line"><tt class="py-comment">#        self.client.serInit()</tt> </tt>
<a name="L521"></a><tt class="py-lineno">521</tt>  <tt class="py-line"><tt class="py-comment">#        self.spitSetup(freq)</tt> </tt>
<a name="L522"></a><tt class="py-lineno">522</tt>  <tt class="py-line"><tt class="py-comment">#        packetTemp = [0,0,0,0,0,0,0,0]</tt> </tt>
<a name="L523"></a><tt class="py-lineno">523</tt>  <tt class="py-line"><tt class="py-comment">#        #form a basic packet</tt> </tt>
<a name="L524"></a><tt class="py-lineno">524</tt>  <tt class="py-line"><tt class="py-comment">#        </tt> </tt>
<a name="L525"></a><tt class="py-lineno">525</tt>  <tt class="py-line"><tt class="py-comment">#        #### split SID into different regs</tt> </tt>
<a name="L526"></a><tt class="py-lineno">526</tt>  <tt class="py-line"><tt class="py-comment">#        SIDlow = (standardId &amp; 0x07) &lt;&lt; 5;  # get SID bits 2:0, rotate them to bits 7:5</tt> </tt>
<a name="L527"></a><tt class="py-lineno">527</tt>  <tt class="py-line"><tt class="py-comment">#        SIDhigh = (standardId &gt;&gt; 3) &amp; 0xFF; # get SID bits 10:3, rotate them to bits 7:0</tt> </tt>
<a name="L528"></a><tt class="py-lineno">528</tt>  <tt class="py-line"><tt class="py-comment">#        </tt> </tt>
<a name="L529"></a><tt class="py-lineno">529</tt>  <tt class="py-line"><tt class="py-comment">#        packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs</tt> </tt>
<a name="L530"></a><tt class="py-lineno">530</tt>  <tt class="py-line"><tt class="py-comment">#                  0x08, # bit 6 must be set to 0 for data frame (1 for RTR) </tt> </tt>
<a name="L531"></a><tt class="py-lineno">531</tt>  <tt class="py-line"><tt class="py-comment">#                  # lower nibble is DLC                   </tt> </tt>
<a name="L532"></a><tt class="py-lineno">532</tt>  <tt class="py-line"><tt class="py-comment">#                 packetTemp[0],packetTemp[1],packetTemp[2],packetTemp[3],packetTemp[4],packetTemp[5],packetTemp[6],packetTemp[7]]</tt> </tt>
<a name="L533"></a><tt class="py-lineno">533</tt>  <tt class="py-line"><tt class="py-comment">#        </tt> </tt>
<a name="L534"></a><tt class="py-lineno">534</tt>  <tt class="py-line"><tt class="py-comment">#        </tt> </tt>
<a name="L535"></a><tt class="py-lineno">535</tt>  <tt class="py-line"><tt class="py-comment">#        #get folder information (based on today's date)</tt> </tt>
<a name="L536"></a><tt class="py-lineno">536</tt>  <tt class="py-line"><tt class="py-comment">#        now = datetime.datetime.now()</tt> </tt>
<a name="L537"></a><tt class="py-lineno">537</tt>  <tt class="py-line"><tt class="py-comment">#        datestr = now.strftime("%Y%m%d")</tt> </tt>
<a name="L538"></a><tt class="py-lineno">538</tt>  <tt class="py-line"><tt class="py-comment">#        path = self.DATA_LOCATION+"InjectedData/"+datestr+"_GenerationFuzzedPackets.csv"</tt> </tt>
<a name="L539"></a><tt class="py-lineno">539</tt>  <tt class="py-line"><tt class="py-comment">#        filename = path</tt> </tt>
<a name="L540"></a><tt class="py-lineno">540</tt>  <tt class="py-line"><tt class="py-comment">#        outfile = open(filename,'a');</tt> </tt>
<a name="L541"></a><tt class="py-lineno">541</tt>  <tt class="py-line"><tt class="py-comment">#        dataWriter = csv.writer(outfile,delimiter=',');</tt> </tt>
<a name="L542"></a><tt class="py-lineno">542</tt>  <tt class="py-line"><tt class="py-comment">#        #dataWriter.writerow(['# Time     Error        Bytes 1-13']);</tt> </tt>
<a name="L543"></a><tt class="py-lineno">543</tt>  <tt class="py-line"><tt class="py-comment">#        #dataWriter.writerow(['#' + description])</tt> </tt>
<a name="L544"></a><tt class="py-lineno">544</tt>  <tt class="py-line"><tt class="py-comment">#            </tt> </tt>
<a name="L545"></a><tt class="py-lineno">545</tt>  <tt class="py-line"><tt class="py-comment">#        numIds = len(standardIDs)</tt> </tt>
<a name="L546"></a><tt class="py-lineno">546</tt>  <tt class="py-line"><tt class="py-comment">#        fuzzNumber = 0;</tt> </tt>
<a name="L547"></a><tt class="py-lineno">547</tt>  <tt class="py-line"><tt class="py-comment">#        while( fuzzNumber &lt; Fuzzes):</tt> </tt>
<a name="L548"></a><tt class="py-lineno">548</tt>  <tt class="py-line"><tt class="py-comment">#            id_new = standsardIDs[random.randint(0,numIds-1)]</tt> </tt>
<a name="L549"></a><tt class="py-lineno">549</tt>  <tt class="py-line"><tt class="py-comment">#            #### split SID into different regs</tt> </tt>
<a name="L550"></a><tt class="py-lineno">550</tt>  <tt class="py-line"><tt class="py-comment">#            SIDlow = (id_new &amp; 0x07) &lt;&lt; 5;  # get SID bits 2:0, rotate them to bits 7:5</tt> </tt>
<a name="L551"></a><tt class="py-lineno">551</tt>  <tt class="py-line"><tt class="py-comment">#            SIDhigh = (id_new &gt;&gt; 3) &amp; 0xFF; # get SID bits 10:3, rotate them to bits 7:0</tt> </tt>
<a name="L552"></a><tt class="py-lineno">552</tt>  <tt class="py-line"><tt class="py-comment">#            packet[0] = SIDhigh</tt> </tt>
<a name="L553"></a><tt class="py-lineno">553</tt>  <tt class="py-line"><tt class="py-comment">#            packet[1] = SIDlow</tt> </tt>
<a name="L554"></a><tt class="py-lineno">554</tt>  <tt class="py-line"><tt class="py-comment">#            </tt> </tt>
<a name="L555"></a><tt class="py-lineno">555</tt>  <tt class="py-line"><tt class="py-comment">#            #generate a fuzzed packet</tt> </tt>
<a name="L556"></a><tt class="py-lineno">556</tt>  <tt class="py-line"><tt class="py-comment">#            for i in range(0,8): # for each databyte, fuzz it</tt> </tt>
<a name="L557"></a><tt class="py-lineno">557</tt>  <tt class="py-line"><tt class="py-comment">#                idx = "db%d"%i</tt> </tt>
<a name="L558"></a><tt class="py-lineno">558</tt>  <tt class="py-line"><tt class="py-comment">#                limits = dbLimits[idx]</tt> </tt>
<a name="L559"></a><tt class="py-lineno">559</tt>  <tt class="py-line"><tt class="py-comment">#                value = random.randint(limits[0],limits[1]) #generate pseudo-random integer value</tt> </tt>
<a name="L560"></a><tt class="py-lineno">560</tt>  <tt class="py-line"><tt class="py-comment">#                packet[i+5] = value</tt> </tt>
<a name="L561"></a><tt class="py-lineno">561</tt>  <tt class="py-line"><tt class="py-comment">#            </tt> </tt>
<a name="L562"></a><tt class="py-lineno">562</tt>  <tt class="py-line"><tt class="py-comment">#            #put a rough time stamp on the data and get all the data bytes    </tt> </tt>
<a name="L563"></a><tt class="py-lineno">563</tt>  <tt class="py-line"><tt class="py-comment">#            row = [time.time(), standardId,8]</tt> </tt>
<a name="L564"></a><tt class="py-lineno">564</tt>  <tt class="py-line"><tt class="py-comment">#            msg = "Injecting: "</tt> </tt>
<a name="L565"></a><tt class="py-lineno">565</tt>  <tt class="py-line"><tt class="py-comment">#            for i in range(5,13):</tt> </tt>
<a name="L566"></a><tt class="py-lineno">566</tt>  <tt class="py-line"><tt class="py-comment">#                row.append(packet[i])</tt> </tt>
<a name="L567"></a><tt class="py-lineno">567</tt>  <tt class="py-line"><tt class="py-comment">#                msg += " %d"%packet[i]</tt> </tt>
<a name="L568"></a><tt class="py-lineno">568</tt>  <tt class="py-line"><tt class="py-comment">#            #print msg</tt> </tt>
<a name="L569"></a><tt class="py-lineno">569</tt>  <tt class="py-line"><tt class="py-comment">#            dataWriter.writerow(row)</tt> </tt>
<a name="L570"></a><tt class="py-lineno">570</tt>  <tt class="py-line"><tt class="py-comment">#            self.client.txpacket(packet)</tt> </tt>
<a name="L571"></a><tt class="py-lineno">571</tt>  <tt class="py-line"><tt class="py-comment">#            #inject the packet repeatily </tt> </tt>
<a name="L572"></a><tt class="py-lineno">572</tt>  <tt class="py-line"><tt class="py-comment">#            for i in range(1,writesPerFuzz):</tt> </tt>
<a name="L573"></a><tt class="py-lineno">573</tt>  <tt class="py-line"><tt class="py-comment">#                self.client.MCPrts(TXB0=True)</tt> </tt>
<a name="L574"></a><tt class="py-lineno">574</tt>  <tt class="py-line"><tt class="py-comment">#                time.sleep(period/1000)</tt> </tt>
<a name="L575"></a><tt class="py-lineno">575</tt>  <tt class="py-line"><tt class="py-comment">#            fuzzNumber += 1</tt> </tt>
<a name="L576"></a><tt class="py-lineno">576</tt>  <tt class="py-line"><tt class="py-comment">#        print "Fuzzing Complete"   </tt> </tt>
<a name="L577"></a><tt class="py-lineno">577</tt>  <tt class="py-line"><tt class="py-comment">#        outfile.close()</tt> </tt>
<a name="L578"></a><tt class="py-lineno">578</tt>  <tt class="py-line"> </tt><script type="text/javascript">
<!--
expandto(location.href);
// -->
</script>
</pre>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Wed Mar  6 20:20:31 2013
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
